Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

test for empty query_result variable

Codes here !

Moderators: macek, egami, gesf

test for empty query_result variable

Postby audiolizard » Fri Nov 08, 2002 8:48 pm

I'm using a query to pull records from a database and display them on a webpage. I want to set up a conditional so that when no results are returned I display a message instead of a blank page. I'm sure this is easy, but nothing I've tried seems to work.

$query = "query...";
$query_result = mysql_query($query, $db_connection);
if(CONDITIONAL){
while ($row = mysql_fetch_array($query_result, MYSQL_ASSOC)){
//do stuff with $row
}
}else{
echo "No results were found";
}

What should I use for CONDITIONAL?

I've tried:
if($query_result){
if($query_result != NULL){
if($query_result != ""){

but I still just get a blank page if there are no results found. :?
So what should I use instead?
audiolizard
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Oct 14, 2002 2:58 pm

Postby Oleg Butuzov » Sat Nov 09, 2002 5:36 am

Code: Select all
if (mysql_num_rows($result) != "0")
{

}
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.