Jump to content

mySQL query successful/unsuccessful handling


rathfon

Recommended Posts

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."
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.