I’m looking for a MySQL command (with php) that selects the most recent row made, or selects all of the row(s) with a certain auto-increment cell being above the number specified.
@clairec666May 28.2004 — #Well if you are using auto-increment, the most recent row will be the one with the highest number in the auto-increment column. for example:
$sql = "SELECT * FROM table";
$result = mysql_query($sql, $conn);
$rows = mysql_num_rows($result);
$sql2 = "SELECT * FROM table where id='$rows'";
A few problems you might come across:
1) If any of the rows have previously been deleted. In that case, $rows won't give you the highest value.....
Instead, you should try $sql = "SELECT * FROM table order by id";
Load it into an array, and take the last number in the array. Then use this in the second sql statement.
2) My typing errors! I'm writing this off the top of my head, so there might be a few mistakes..... sorry!