dbutler Posted September 29, 2008 Share Posted September 29, 2008 below is a snippet of code I have in my application: $glid = 39102;$query = "select distinct account from PROJECTS where glid='$glid' order by account";$result = mysql_query($query) or die ("Couldn't select distinct accounts");$row = mysql_fetch_array($result, MYSQL_ASSOC);foreach ($row as $account) { echo "account $account<br>\n"; }print_r($row); when I run this I get a single account echoed from the foreach statement and the print_r shows me the array with a single item in it as below (this is the screen output of the above):account LEADJArray ( [account] => LEADJ ) My issue is that when I run the $query above directly in MySQL, I get a list of 24 accounts, not just the one that is output from my code. Can anyone think of why this is the case? I have tried MYSQL_NUM and MYSQL_BOTH as well in the fetch array function but neither of those made a difference. Any help is appreciated...drb Link to comment Share on other sites More sharing options...
jeffman Posted September 29, 2008 Share Posted September 29, 2008 mysql_fetch_array() doesn't return all the rows in $result. You need to put it in a loop to get all the rows. It self iterates. See the examples here: http://us2.php.net/manual/en/function.mysql-fetch-array.php Link to comment Share on other sites More sharing options...
dbutler Posted September 29, 2008 Author Share Posted September 29, 2008 That does it! I put the foreach inside the while loop and it works. Thanks!!! drb Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.