Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I check if values returned from an SQL/PHP query are empty?

Tags:

php

mysql

How would I check to see if the values returned from an sql query are empty? I tried using if(empty($var)), but that didnt work either. heres my code

PHP Code:

        while($row = mysql_fetch_array($Result)) 
        { 
            if(count($row) == 0) 
            { 
                .... 
            } 
       } 

How would i check to see if $row is empty?

like image 770
Naeem Ul Wahhab Avatar asked Dec 06 '22 17:12

Naeem Ul Wahhab


1 Answers

This is the right way to do this, you can check if the results are empty by finding number of row in returned results. There is a function in sql to do this mysql_num_rows. Here is the method to use it:

if (mysql_num_rows($Result) == 0) { 
   //results are empty, do something here 
} else { 
   while($admin_row = mysql_fetch_array($Result)) { 
      //processing when you have some data 
}  
like image 184
Naeem Ul Wahhab Avatar answered Dec 10 '22 13:12

Naeem Ul Wahhab