473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

ARRAY - straightforward question?

Hi,

I've got a database that outputs markers on a google map project. The
problem I am encountering is that some businesses have been located the same
latitude and longitude, therefore markers don't show (others are underneath
the top one). So, I need to get this MySQL output, parse it through an array
creating an output such as

(-0.28183499,51.37974167), biz1 biz2 biz3
(-0.28301400,51.38087463), biz4
(-0.28151301,51.38144684), biz5
(-0.28693399,51.38250351), biz6
(-0.28626299,51.38276672), biz7
(-0.29334599,51.38436890), biz8 biz9 biz10
(-0.29725999,51.38850021), biz11 biz12
(-0.29800400,51.38896179), biz13 biz14

Here's an example of my input data as it is at the moment ..

(-0.28183499,51.37974167), biz1
(-0.28183499,51.37974167), biz2
(-0.28183499,51.37974167), biz3
(-0.28301400,51.38087463), biz4
(-0.28151301,51.38144684), biz5
(-0.28693399,51.38250351), biz6
(-0.28626299,51.38276672), biz7
(-0.29334599,51.38436890), biz8
(-0.29334599,51.38436890), biz9
(-0.29334599,51.38436890), biz10
(-0.29725999,51.38850021), biz11
(-0.29725999,51.38850021), biz12
(-0.29800400,51.38896179), biz13
(-0.29800400,51.38896179), biz14

I already sort the data by latitude, so they will always be next to each
other. But I am going to be writing this using AJAX and need the fastest
solution possible. There could be hundreds needed to be parsed in a split
second.

Thanks for any pointers.
Apr 30 '06 #1
5 1283
Use an associative array with the coordinates as the key. That way any biz
that has the same coords will appear under that key in the array.

while($row = mysql_fetch_assoc($result)) {
$data[ $row['coordinates'] ][] = $row['bizname'];
}

Note, 'coordinates' and 'bizname' are the db cols, your db col name will
probably differ from my example.
Also note second set of empty square braces. These create a new var under
that key, otherwise you'd just be overwriting the last bizname you saved.

"elyob" <ne*********@gmail.com> wrote in message
news:44********@news1.homechoice.co.uk...
Hi,

I've got a database that outputs markers on a google map project. The
problem I am encountering is that some businesses have been located the
same latitude and longitude, therefore markers don't show (others are
underneath the top one). So, I need to get this MySQL output, parse it
through an array creating an output such as

(-0.28183499,51.37974167), biz1 biz2 biz3
(-0.28301400,51.38087463), biz4
(-0.28151301,51.38144684), biz5
(-0.28693399,51.38250351), biz6
(-0.28626299,51.38276672), biz7
(-0.29334599,51.38436890), biz8 biz9 biz10
(-0.29725999,51.38850021), biz11 biz12
(-0.29800400,51.38896179), biz13 biz14

Here's an example of my input data as it is at the moment ..

(-0.28183499,51.37974167), biz1
(-0.28183499,51.37974167), biz2
(-0.28183499,51.37974167), biz3
(-0.28301400,51.38087463), biz4
(-0.28151301,51.38144684), biz5
(-0.28693399,51.38250351), biz6
(-0.28626299,51.38276672), biz7
(-0.29334599,51.38436890), biz8
(-0.29334599,51.38436890), biz9
(-0.29334599,51.38436890), biz10
(-0.29725999,51.38850021), biz11
(-0.29725999,51.38850021), biz12
(-0.29800400,51.38896179), biz13
(-0.29800400,51.38896179), biz14

I already sort the data by latitude, so they will always be next to each
other. But I am going to be writing this using AJAX and need the fastest
solution possible. There could be hundreds needed to be parsed in a split
second.

Thanks for any pointers.

Apr 30 '06 #2

"Jimbus" <mr**********@yahoo.com> wrote in message
news:Y675g.5024$XV5.4781@fed1read10...
Use an associative array with the coordinates as the key. That way any biz
that has the same coords will appear under that key in the array.

while($row = mysql_fetch_assoc($result)) {
$data[ $row['coordinates'] ][] = $row['bizname'];
}

Note, 'coordinates' and 'bizname' are the db cols, your db col name will
probably differ from my example.
Also note second set of empty square braces. These create a new var under
that key, otherwise you'd just be overwriting the last bizname you saved.


Thanks, my coordinates are currently split into "latitude" and "longitude"
cols, although I will also be soon using the geospatial functionality in
mysql. (Geomotry Point etc).

So, should I be looking to do something like this ... ?

while($row = mysql_fetch_assoc($result)) {
$data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
}

Thanks
Apr 30 '06 #3
elyob wrote:
while($row = mysql_fetch_assoc($result)) {
$data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
}


while($row = mysql_fetch_assoc($result))
$data[$row['longitude']][$row['latitude']][] = $row['bizname'];

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Apr 30 '06 #4
> Thanks, my coordinates are currently split into "latitude" and "longitude"
cols, although I will also be soon using the geospatial functionality in
mysql. (Geomotry Point etc).

So, should I be looking to do something like this ... ?

while($row = mysql_fetch_assoc($result)) {
$data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
}


That's how I'd do it... concatenating the lat and long. Someone else replied
with a 3D array solution, which might be better in terms of speed. Not sure
about that though.

Anyone have an analysis of which would be faster? A longer array key vs. a
3D array.
May 1 '06 #5

"Jimbus" <mr**********@yahoo.com> wrote in message
news:WPe5g.5058$XV5.3974@fed1read10...
Thanks, my coordinates are currently split into "latitude" and
"longitude" cols, although I will also be soon using the geospatial
functionality in mysql. (Geomotry Point etc).

So, should I be looking to do something like this ... ?

while($row = mysql_fetch_assoc($result)) {
$data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
}


That's how I'd do it... concatenating the lat and long. Someone else
replied with a 3D array solution, which might be better in terms of speed.
Not sure about that though.

Anyone have an analysis of which would be faster? A longer array key vs. a
3D array.


Right, now I've got that array ... how am I going to print out the results?
Sorry for my numptiness, but I usually rely on MySQL doing all the work.

In fact, perhaps I ought to look at MySQL doing all the work instead of
using an array?

May 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so...
4
by: Gent | last post by:
Below is a straightforward C++ question but i'm giving example code to demonstrate the issue i'm having. THe issue might seem to be out of the topic but it's mostly related to C++ and is not...
4
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax...
12
by: flipflop | last post by:
I need to create a global array whose dimensions depend on the contents of another global array populated at its initialisation. For example: int array1={3,2,1}; int array2]; //should be...
27
by: pkirk25 | last post by:
Assume an array of structs that is having rows added at random. By the time it reaches your function, you have no idea if it has a few hundred over over 10000 rows. When your function recieves...
12
by: amer.terzic | last post by:
Here's what my code is supposed to do (it seems to work fine) Take a char* array and remove a first character from it....as simple as that. The mentioned char* array is a 'global' var shared...
26
by: mike-yue | last post by:
The topic comes from a question: Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1Quicksort 2Linear Search 3Bubble Sort ...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.