Clinton Posted January 3, 2009 Share Posted January 3, 2009 How can I change the code below so that if it returns 0 rows it doesn't error out and instead say something like "nothing found"? $sql = "SELECT * FROM thelist WHERE dp = $sr ORDER BY jp"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { extract($row); Link to comment https://forums.phpfreaks.com/topic/139347-solved-while-return-0-rows/ Share on other sites More sharing options...
GingerRobot Posted January 3, 2009 Share Posted January 3, 2009 See here. Same question was asked a few hours ago. Link to comment https://forums.phpfreaks.com/topic/139347-solved-while-return-0-rows/#findComment-728858 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2009 Share Posted January 3, 2009 A query that executes but matches zero rows in the database does not produce an error in the code you posted. If you are getting an error at the mysql_fetch_array() it means your query failed to execute, either due to a database server problem, no database selected, or a syntax error in your query. What is the actual error you are getting? Link to comment https://forums.phpfreaks.com/topic/139347-solved-while-return-0-rows/#findComment-728879 Share on other sites More sharing options...
Clinton Posted January 3, 2009 Author Share Posted January 3, 2009 TY. I searched the threads but didn't find anything useful. Also, yea... you're right. The error was actually in my WHERE syntax. But I still needed the num_rows so I could express what was happening. Thank you. Link to comment https://forums.phpfreaks.com/topic/139347-solved-while-return-0-rows/#findComment-728881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.