Onz Onz - 1 year ago 79
MySQL Question

Get last ID and display it

I've been looking around but most of the tutorials are showing the

but it's on the same document. I'm wondering if there is a way where you can get the last id of a column and echo it out.

$image = mysql_query("SELECT * FROM images WHERE id=$id");
$image = mysql_fetch_assoc($image) or die(mysql_error());

$image = $image['image'];

header("Content-type: image/jpeg");

echo $image;

This is my code that gets the image from the database and makes the blob into a id?=1 which is the picture but as php. That is a uploader from another php document but I'm typing to output the last id from that column on another page (Not the picture but the number for statistics)

A bit of code that could do that would be very helpful.

Answer Source

This would grab the row with the highest ID:

$result = mysql_query("SELECT MAX(id) FROM images");
$row = mysql_fetch_row($result);
// $row[0] contains the value of the highest id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download