php - How to set min(value) variable as 0 when no value is returned by the sql query -


$sql = "select min(id) sid table1 ...."; $result = mysql_query($sql); $row = mysql_fetch_array($result); $sid = $row['sid']; 

how can set $sid 0, when no value returned sql query

(here id in table1 int type)

please me....

if there no matching rows, min() function return null value, use coalesce or ifnull() turn zero:

select coalesce(min(id), 0) sid ... select ifnull(min(id), 0) sid ... 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -