ARRAY - straightforward question?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elyob

    #1

    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.3 7974167), biz1 biz2 biz3
    (-0.28301400,51.3 8087463), biz4
    (-0.28151301,51.3 8144684), biz5
    (-0.28693399,51.3 8250351), biz6
    (-0.28626299,51.3 8276672), biz7
    (-0.29334599,51.3 8436890), biz8 biz9 biz10
    (-0.29725999,51.3 8850021), biz11 biz12
    (-0.29800400,51.3 8896179), biz13 biz14

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

    (-0.28183499,51.3 7974167), biz1
    (-0.28183499,51.3 7974167), biz2
    (-0.28183499,51.3 7974167), biz3
    (-0.28301400,51.3 8087463), biz4
    (-0.28151301,51.3 8144684), biz5
    (-0.28693399,51.3 8250351), biz6
    (-0.28626299,51.3 8276672), biz7
    (-0.29334599,51.3 8436890), biz8
    (-0.29334599,51.3 8436890), biz9
    (-0.29334599,51.3 8436890), biz10
    (-0.29725999,51.3 8850021), biz11
    (-0.29725999,51.3 8850021), biz12
    (-0.29800400,51.3 8896179), biz13
    (-0.29800400,51.3 8896179), 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.


  • Jimbus

    #2
    Re: ARRAY - straightforward question?

    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_ass oc($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" <newsprofile@gm ail.com> wrote in message
    news:4454f07a$1 @news1.homechoi ce.co.uk...[color=blue]
    > 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.3 7974167), biz1 biz2 biz3
    > (-0.28301400,51.3 8087463), biz4
    > (-0.28151301,51.3 8144684), biz5
    > (-0.28693399,51.3 8250351), biz6
    > (-0.28626299,51.3 8276672), biz7
    > (-0.29334599,51.3 8436890), biz8 biz9 biz10
    > (-0.29725999,51.3 8850021), biz11 biz12
    > (-0.29800400,51.3 8896179), biz13 biz14
    >
    > Here's an example of my input data as it is at the moment ..
    >
    > (-0.28183499,51.3 7974167), biz1
    > (-0.28183499,51.3 7974167), biz2
    > (-0.28183499,51.3 7974167), biz3
    > (-0.28301400,51.3 8087463), biz4
    > (-0.28151301,51.3 8144684), biz5
    > (-0.28693399,51.3 8250351), biz6
    > (-0.28626299,51.3 8276672), biz7
    > (-0.29334599,51.3 8436890), biz8
    > (-0.29334599,51.3 8436890), biz9
    > (-0.29334599,51.3 8436890), biz10
    > (-0.29725999,51.3 8850021), biz11
    > (-0.29725999,51.3 8850021), biz12
    > (-0.29800400,51.3 8896179), biz13
    > (-0.29800400,51.3 8896179), 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.
    >[/color]


    Comment

    • elyob

      #3
      Re: ARRAY - straightforward question?


      "Jimbus" <mrbiggles909@y ahoo.com> wrote in message
      news:Y675g.5024 $XV5.4781@fed1r ead10...[color=blue]
      > 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_ass oc($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.[/color]

      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_ass oc($result)) {
      $data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
      }

      Thanks


      Comment

      • Toby Inkster

        #4
        Re: ARRAY - straightforward question?

        elyob wrote:
        [color=blue]
        > while($row = mysql_fetch_ass oc($result)) {
        > $data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
        > }[/color]

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

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

        Comment

        • Jimbus

          #5
          Re: ARRAY - straightforward question?

          > Thanks, my coordinates are currently split into "latitude" and "longitude"[color=blue]
          > 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_ass oc($result)) {
          > $data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
          > }[/color]

          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.


          Comment

          • elyob

            #6
            Re: ARRAY - straightforward question?


            "Jimbus" <mrbiggles909@y ahoo.com> wrote in message
            news:WPe5g.5058 $XV5.3974@fed1r ead10...[color=blue][color=green]
            >> 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_ass oc($result)) {
            >> $data[ $row['longitude'].$row['latitude'] ][] = $row['bizname'];
            >> }[/color]
            >
            > 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.[/color]

            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?



            Comment

            Working...