Evaluating a Result Set
Posted: Sun Dec 14, 2008 9:50 am
This is so basic - I feel like a complete idiot having to ask about this - but I've spent an hour trying to get this code to work right and it still won't. Can anyone here tell me WHY this script always dies with no results even though the SQL successfully brings up a row when I execute it in phpMyAdmin?
How do you evaluate for an empty result set to throw an error?
Code: Select all
$sql = "SELECT * FROM `table` WHERE `id` = '" . $id . "'";
$res = mysql_query($sql);
// die ("$sql"); // Display the $sql for testing in phpMyAdmin
$num = mysql_num_rows($res);
if ($num == 0);
{
die ("Not a valid client lookup.");
}
$Row = mysql_fetch_assoc($res);
$url = $Row['url'];