Re: php - no results - display other message

From: Date: Wed, 15 Sep 2004 14:11:26 +0000
Subject: Re: php - no results - display other message
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-196730@lists.php.net to get a copy of this message
Or alternatively $result = mysql_query("SELECT * FROM tablename"); if (mysql_num_rows($result)) { while ($row = mysql_fetch_row($result)) { // display results } } else echo "No results"; Hope this helps Cheers Chris John Nichel wrote:
Dustin Krysak wrote:
Hi there... I have a simple search page (mysql database), and I can get it to display the results no issues, but i was wondering how I could display a message stating there were no results, instead of just having the field blank. I am familiar with IF and ELSE statements, but I am not sure how to test the "no result" option from the results of a SQL query.... thanks! d
Depends on how you're recieving your results... function doSearch ( $string ) {
    $sql = "SELECT *.....blah, blah
    more code;
    if ( $result = ....
        return $result;
    } else {
        return false;
    }
} if ( $search = doSearch ( $terms ) ) {
    // display results
} else {
    // display no results found
}


« previous php.general (#196730) next »