Re: creating an array from a mySQL query



To take your $result, and put it into an array, you need to feed each
row of
an array through a loop. The best way that I like is to use a while
loop, and put
it into an array. Although it does get complicated attempting to do
multi-dimensional
associative arrays, I would suggest using the constant MYSQL_BOTH as
the type of
array to put it into. In your case, to fetch the array and put it into
an array, it would
look like this.

// Grab all coordinates and put them in an array
while ( $row = mysql_fetch_array( $result, MYSQL_BOTH ) {
$coordinates[] = $row;
}

Using both associative and a numerical array, you can then use a for
loop to cycle through
all coordinates like this. Using the associtive array, you can use
this to define the fields inside
the second dimension of the array.



My apologies, for I forgot to add something. You need to specify
that you are in the $i array when you are doing this. So, the correct
way to cycle through it would be this.

for ($i = 0; $i < count($coordinates); $i++) {
print "var longitude = $coordinates[$i]['long']";
print "var namelong = $coordinates[$i]['name_long']";
print "var address = $coordinates[$i]['addr_num']";
print "var stname = $coordinates[$i]['st_namefull']";

// Do whatever processing is required to map the coordinate and
then continue to the next.

}

Hope this helps.

Respectfully Submitted,
Huck Finn

.



Relevant Pages

  • rotate revisited
    ... Suppose we have an array A containing n equi-spaced elements. ... The cost of this method (excluding loop costs) is: ... Each cycle is of length n/d. ... I will use the term "small slide" for a data move that is less ...
    (comp.programming)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • Re: COBOL myth busted, index versus subscript (MF on HP)
    ... curious about an array without an index defined, ... So, Question, what is exit perform cycle? ... When I first ran the test, the null loop was empty. ...
    (comp.lang.cobol)