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); Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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.