[SOLVED] Using mysql_fetch_array()
Posted: Sat Sep 11, 2004 12:20 pm
Let's say I have a table called states with only two colums. Column 1 (abbr) is the two letter abbreviation for the state and column 2 (full) is the full name for the state.
Now I grab all the table data like this:
Now my questions is how do I access the data within this array called $myArray? I assumed that the abbr column was the key and the full column was the value. So, I tried $myArray[CA] thinking it would return California, but got zip.
I know that I can use this array in a loop to access all the data by rows using $myArray[abbr] and $myArray[full]. It seems that using mysql_fetch_array doesn't set the key=>value pairing as I thought it would.
Obviously, I'm missing something here, but I just don't know enough to spot it on my own. The two books I'm using to teach myself PHP have failed me this instance.
Anyone? Thanks in advance!
Now I grab all the table data like this:
Code: Select all
<?php
$results=mysql_query("SELECT * FROM states");
$myArray=mysql_fetch_array($states);
?>I know that I can use this array in a loop to access all the data by rows using $myArray[abbr] and $myArray[full]. It seems that using mysql_fetch_array doesn't set the key=>value pairing as I thought it would.
Obviously, I'm missing something here, but I just don't know enough to spot it on my own. The two books I'm using to teach myself PHP have failed me this instance.
Anyone? Thanks in advance!