rathfon Posted June 1, 2006 Share Posted June 1, 2006 Ok, I've got the query working fine, it is to find the row in the table and then displays the data. Well, if I give it something it can find it displays what I need and works perfectly.But if I give it something it can't, it won't return an error (obviously because the query worked fine, just couldn't find anything to return), so how do I go about handling that?[code]$link = mysql_connect($db_server, $db_user, $db_password) or die("Could not connect.");mysql_select_db($db_name) or die("Could not select database.");$query = "SELECT * FROM images WHERE idnumber=('$id')";$result = mysql_query($query) or die("Oops, a no go.");while ($line = mysql_fetch_assoc($result)) {// all that other stuff, above and below[/code]Like I said, works perfectly it's just I want to be able to handle when it doesn't find anything. I tried echoing the $result after it looks for $id that it won't find, but it just gives me "Resource ID #2." Quote Link to comment https://forums.phpfreaks.com/topic/10931-mysql-query-successfulunsuccessful-handling/ Share on other sites More sharing options...
samshel Posted June 1, 2006 Share Posted June 1, 2006 [code]if(mysql_num_rows($result) == 0 ) { echo "No Rows Found";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10931-mysql-query-successfulunsuccessful-handling/#findComment-40818 Share on other sites More sharing options...
rathfon Posted June 1, 2006 Author Share Posted June 1, 2006 [!--quoteo(post=378970:date=Jun 1 2006, 03:21 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ Jun 1 2006, 03:21 AM) [snapback]378970[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]if(mysql_num_rows($result) == 0 ) { echo "No Rows Found";}[/code][/quote]Thank you, don't know how I missed that. Quote Link to comment https://forums.phpfreaks.com/topic/10931-mysql-query-successfulunsuccessful-handling/#findComment-40821 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.