Page 1 of 1

checking return value of max()

Posted: Mon Jan 23, 2012 6:12 pm
by new_php_coder
Hello all,

I want to check whether

Code: Select all

Code: Select all
 $query="SELECT max( id ) as maxnum FROM `tbl_customer`";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
$myid=$row[maxnum];
returns null/zero. If it is null/zero i.e. no records in tbl_customer then i want id to be 1 else start from 1+id.

I tried

Code: Select all

Code: Select all
if($myid!=""){
      $myid=$myid+1;
   echo "Hello". $myid;
}
else{
   $myid=1;
echo "Hellonull". $myid;
}
Can somebody guide me what is wrong in my code or how to check query with max() result?

Thanks in advance.

Re: checking return value of max()

Posted: Tue Jan 24, 2012 12:22 am
by social_experiment
Have you tried $myid = $row[0] ?