Jump to content


Photo

mySQL query successful/unsuccessful handling


  • Please log in to reply
2 replies to this topic

#1 rathfon

rathfon
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 June 2006 - 07:17 AM

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?

$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

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."

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 June 2006 - 07:21 AM

if(mysql_num_rows($result) == 0 ) {
  echo "No Rows Found";
}


Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 rathfon

rathfon
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 01 June 2006 - 07:32 AM

[!--quoteo(post=378970:date=Jun 1 2006, 03:21 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ Jun 1 2006, 03:21 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if(mysql_num_rows($result) == 0 ) {
  echo "No Rows Found";
}

[/quote]

Thank you, don't know how I missed that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users