Shwaza Posted October 15, 2006 Share Posted October 15, 2006 Hi, thanks for reading this :).I have a really weird problem in a script I'm writing and I can't think of what could possibly cause it. Here is the code I'm using:[code]$sql = "SELECT ID FROM ". $table. "_choices";$query = mysql_query($sql) or die("A MySQL error occurred: ". mysql_error());echo "mysql_num_rows - ". mysql_num_rows($query). "<br />";echo "count mysql_fetch_array - ". count(mysql_fetch_array($query));[/code]I put the two echo's in to determine my problem. The problem is that the output text is: mysql_num_rows - 5count mysql_fetch_array - 2There SHOULD be 5 rows, but why would mysql_fetch_array() only return 2 even when mysql_num_rows told me there's 5. I'm 100% positive there are 5 rows in there, and I can't understand why mysql_fetch_array() wouldn't return them all :S.If anyone could help it would be MUCH appreciated!Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/24004-very-strange-mysql-problem/ Share on other sites More sharing options...
sasa Posted October 15, 2006 Share Posted October 15, 2006 mysql_fetch_array($query) extract one row from $query in arraythis array have two elements it looks like array(0 => 1, 'ID' => 1)your output is OK Quote Link to comment https://forums.phpfreaks.com/topic/24004-very-strange-mysql-problem/#findComment-109098 Share on other sites More sharing options...
Shwaza Posted October 15, 2006 Author Share Posted October 15, 2006 That makes sense, however when I use it in the loop for my process it only works for ID 1 and 4 :S. The process looks like:while( $r = mysql_fetch_array($query) ){ ... (the process)}and if I echo out the IDs each time the loop runs through it only comes up with 1 and 4 :S. If I just do:while( $r = mysql_fetch_array($query) ){ echo $r['ID']. " ";}however, it echos out 1 2 3 4 5 like it should :S. Do you know why it might only echo out ID 1 and 4 during the process but echo out all 5 when it's just doing the echo? It makes no sense to me. Quote Link to comment https://forums.phpfreaks.com/topic/24004-very-strange-mysql-problem/#findComment-109121 Share on other sites More sharing options...
Shwaza Posted October 15, 2006 Author Share Posted October 15, 2006 Awh *smacks self in head* I'm so stupid. Inside the loop process I perform another query and I was stupid enough to use the name $query for that query as well so it ended up screwing over the loop.Thanks a lot for your help, it's all fixed now :). Quote Link to comment https://forums.phpfreaks.com/topic/24004-very-strange-mysql-problem/#findComment-109124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.