$checkid="select MAX(sno) from registrants"; $id=mysql_query($checkid) or die("Unable to execute query"); // Max sno is now stored in $ID echo $id; OUTPUT : Resource id #4 Output should be '1' as I have only one row in the table with sno=1