designknights Posted April 12, 2007 Share Posted April 12, 2007 $contents = '<h1>DATABASE ERROR!</h1>'; if ($dbConnect = mysql_connect("my_db","my_user","my_pass")){ mysql_select_db("my_db"); // setting the vars for the function $numovies=0; $i = 0 ; //building an array of movies to be checked out by Movie ID foreach ($post as $key => $value){ if (strlen($key) > { $key = str_split($key,; if ($key[0] == "checkout"){ $themids[$numovies] = $value; //getting the number of movies selected $numovies++; } } } // building the query if ($numovies > 1){ for ($i=0;$i<$numovies;$i++){ if ($i==0){ $query = 'SELECT * FROM `movies` WHERE `MID` = \''.$themids[$i].'\' '; } else if ($i==($numovies-1)){ $query .= 'AND `MID` = \''.$themids[$i].'\' LIMIT 0,'.$i.';'; } else { $query .= 'AND `MID` = \''.$themids[$i].'\' '; } } } elseif ($numovies == 1){ $query = 'SELECT * FROM `movies` WHERE `MID` = \''.$themids[$i].'\' LIMIT 1;'; } else { $query = false; } // query db if ($query != false){ $result = mysql_query($query,$dbConnect) or die ('<br>'.$query.'<br>'.mysql_error()); } else { $contents= "DATABASE ERROR!"; } //loop to output results while ($row = mysql_fetch_assoc($result)) { echo $row["MID"]; echo $row["title"]; echo $row["status"]; } mysql_free_result($result); This function should work. The php manual says so, the mysql manual says so and I have used that while loop many many many times. Is there a reason it has decided not to work here(IE a bug in php that i cant find)? The problem i am having is that if there is more than one row of results from the SQL query the loop dosent actually put anyhing into $row. However if there is only one row returned from the DB then it works fine. I am stumped, any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/ Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 Have you echo'd the $query ? as its kinda hard to read without the code tags and with an unknown input but i can tell you this.. its not a IE bug Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227946 Share on other sites More sharing options...
esukf Posted April 12, 2007 Share Posted April 12, 2007 Its more likely a problem with you sql statement rather than mysql_fetch_assoc(). Echo the sql statement and check its valid <?php // query db if ($query != false){ echo $query; $result = mysql_query($query,$dbConnect) or die ('<br>'.$query.'<br>'.mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227948 Share on other sites More sharing options...
designknights Posted April 12, 2007 Author Share Posted April 12, 2007 this is the query being sent to the MySql server. I have tested it in PhpMyAdmin and it pulls the results fine. $query = SELECT * FROM `movies` WHERE `MID` = '9' AND `MID` = '14' AND `MID` = '18' ; Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227951 Share on other sites More sharing options...
pocobueno1388 Posted April 12, 2007 Share Posted April 12, 2007 You should still try out the suggested error catching methods used above and see if you get any results from it... Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227952 Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 this is the query being sent to the MySql server. I have tested it in PhpMyAdmin and it pulls the results fine. $query = SELECT * FROM `movies` WHERE `MID` = '9' AND `MID` = '14' AND `MID` = '18' ; will return Zero... Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227953 Share on other sites More sharing options...
designknights Posted April 12, 2007 Author Share Posted April 12, 2007 yer right.. i'm retarded Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227957 Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 is it something i said! ??? Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227964 Share on other sites More sharing options...
designknights Posted April 12, 2007 Author Share Posted April 12, 2007 just replaced AND with OR in the query building loop and IMAGINE, THIS! IT WORKS!!! WooT! thanks for pointing that out. Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227967 Share on other sites More sharing options...
MadTechie Posted April 12, 2007 Share Posted April 12, 2007 And all becuase you echo'd the $query Quote Link to comment https://forums.phpfreaks.com/topic/46770-solved-mysql_fetch_assoc-not-working-as-desired-is-this-a-bug-i-dont-know-about/#findComment-227975 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.