
Originally Posted by
lorenw
use
PHP Code:
if(mysql_numrows($res) == '0'){
echo 'no results';
}
else{
// do something
}
That would work under the assumption you are using mysql function syntax (which is discouraged), but I'd rather see you not put the 0 in quotes and use ===
PHP Code:
if (mysql_num_rows($res) === 0)
{
// no results, return your error
}
else
{
// put what you have currently here
}
If you are using mysqli, you can do one of the following
PHP Code:
if (mysqli_stmt_num_rows($res) === 0)
{
// no results, return your error
}
else
{
// put what you have currently here
}
Or
PHP Code:
// assumption you have a $mysqliObject
$stmt = $mysqli->prepare($query)
$stmt->execute();
if ($stmt->num_rows === 0)
{
// no results, return your error
}
else
{
// put what you have currently here
}
Then there is PDO
PHP Code:
$stmt = $dbh->prepare('your query here');
$stmt->execute();
if ($stmt->rowCount() === 0)
{
// no results, return your error
}
else
{
// put what you have currently here
}
Bookmarks