Showing posts with label get Max ID mysql. Show all posts
Showing posts with label get Max ID mysql. Show all posts

Tuesday, August 19, 2008

How to get Max ID row from mysql table using php

Do you need to find the max id of a mysql table? check out the following code.
simply use the sql MAX function to find the max id.

<?php

mysql_connect("localhost","root","");
mysql_select_db(test);

$q = "select MAX(id) from tbl_name";
$result = mysql_query($q);
$data = mysql_fetch_array($result);

echo $data[0];

?>