cbarlow123
cbarlow123

Reputation: 217

If no results found, display (message)

Trying to display a message if no results found in the search query.

Here is a brief example of my code.

$sql = "SELECT * FROM details WHERE ID =1"

$res =& $db->query($sql);
if (PEAR::isError($res)) {
    die($res->getMessage());
}

while($row = $res->fetchRow())
{
     echo 'results'
    {

Any help would be greatly appreciated! Thanks

Upvotes: 1

Views: 389

Answers (1)

Andreas Wong
Andreas Wong

Reputation: 60536

DB_result has a method called numRows(), so you could check

if($res->numRows() == 0)

http://pear.php.net/package/DB/docs/latest/DB/DB_result.html#methodnumRows

Get the number of rows in a result set

Return: the number of rows. A DB_Error object on failure.

And you don't need to worry about DB_Error since it was already checked at

PEAR::isError($res)

Upvotes: 5

Related Questions