Jump to content


Photo

Creating simple array from SQL results


  • Please log in to reply
2 replies to this topic

#1 ViperSBT

ViperSBT
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 27 July 2006 - 02:33 PM

This shouldn't be this difficult...

$statesql = "SELECT id, state FROM state ORDER BY state";
$stateresult = mysql_query($statesql);

while ($temp = mysql_fetch_array($stateresult)){
$sid = $temp["id"];
$sst = $temp["state"];
echo "id = ".$sid."<br>state = ".$sst."<br>";
$statelist[$sid] = $sst;
}


I have run the SELECT statement directly from the DB and get the expected return, but trying to parse it and create an array called statelist is going nowhere....  I included the echo line to see what it was doing, and I am getting a blank page...  So, it would seem to me that it isn't even performning the WHILE statement.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 27 July 2006 - 02:38 PM

Have you tried:
$stateresult = mysql_query($statesql) or die(mysql_error());


#3 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 27 July 2006 - 03:36 PM

Did you run the query on the same db table that your php code is accessing?  Is your server set to display errors?  The code is perfectly fine.  Either the database has not been opened properly or the query result is empty. 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users