mysql - How to check if a query with sql functions like max, count e.t.c. returns NULL? -


how can check if query sql functions max() returns null ? here code:

$query = mysql_query("select max(priority) categories") or die('sel_pri:'.mysql_error());      if(mysql_num_rows($query) > 0)             $max_pri = mysql_result($query, 0) or die('priority:'.mysql_error());     else         $max_pri = 0; 

my categories table epmty, mysql_num_rows() return 1, because query return 1 row null value. code above "dies"! have tryed:

if(empty($query))    if(isset($query)) if(is_null($query)) 

but none of above working either.

in case, can supply default value in sql using coalesce, returns first non-null of it's arguments:

select coalesce(max(priority), 0) categories 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -