Jump to content

Archived

This topic is now archived and is closed to further replies.

rathfon

mySQL query successful/unsuccessful handling

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

Share this post


Link to post
Share on other sites
[code]
if(mysql_num_rows($result) == 0 ) {
  echo "No Rows Found";
}

[/code]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.