I've got a database with 3 records and a field called "id" which is an auto-incrementing field. If I print the contents of the database it correctly lists records with ids of 1, 2 and 3.
However when I try to use the MAX function to return the highest value for id it always returns 1. As I'm new to both PHP and MySQL, can someone with patience and experience point me in the right direction?!
- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
However when I try to use the MAX function to return the highest value for id it always returns 1. As I'm new to both PHP and MySQL, can someone with patience and experience point me in the right direction?!
Code:
// $conn is a handle to the database connection
$result = mysql_query("SELECT id, MAX(id) FROM topics", $conn) or die(mysql_error($conn));
$row = mysql_fetch_array($result);
$lastrec = $row[0];
echo "Most recent record number is " . $lastrec;
Code:
Output is:
Most recent record number is 1
- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments