Aana Saeed
Aana Saeed

Reputation: 299

echoing max or last greater id in a table

I want to get the maximum id from a table.

If I use mysqli_insert_id, then it gives 0 value.Plz help or suggest any other approach to get last/max id from table

$pre_id = $_POST['last_id'];
$sql = mysqli_query($db3->connection, "SELECT * FROM chat where  id=>_pre_id");
$id = mysqli_insert_id($db3->connection);
echo $id;

Upvotes: 0

Views: 53

Answers (2)

Vamsi
Vamsi

Reputation: 873

try this query

SELECT max(id) as maxid FROM chat

Upvotes: 0

Syed Osama
Syed Osama

Reputation: 133

Is that you want ?

SELECT * FROM chat ORDER BY id DESC LIMIT 0,1

Upvotes: 2

Related Questions