test for empty query_result variable

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 3
Joined: Mon Oct 14, 2002 2:58 pm

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);
while ($row = mysql_fetch_array($query_result, MYSQL_ASSOC)){
//do stuff with $row
echo "No results were found";

What should I use for CONDITIONAL?

I've tried:
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?

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

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

Code: Select all

if (mysql_num_rows($result) != "0")


Return to “mySQL & php coding”

Who is online

Users browsing this forum: NigelRen and 3 guests