PDA

Click to See Complete Forum and Search --> : Last record


prokhaled
May 13th, 2002, 03:46 AM
In this code:

$Sql = "select * from $TableName where ID=What? ";

I want to go to last record that it's ID=last ID in the table.

scoutt
May 13th, 2002, 09:39 AM
you want to display tha last ID or row in a table?

$Sql = "select * from $TableName order by ID DESC ";


that should work, make sure you only loop once as it will list all of them. hope thisis what you meant.

chrisjk
May 13th, 2002, 09:42 AM
you can also append LIMIT to the end of that so it only returns 1 record

$Sql = "select * from $TableName order by ID DESC LIMIT 1";

The Hobo
May 13th, 2002, 11:12 AM
or, to get the last id (if they're in order with no breaks), do:


$num = mysql_num_rows(mysql_query("SELECT * FROM $TableName"));

$sql = "SELECT $TableName WHERE ID='$num'";

scoutt
May 13th, 2002, 11:46 AM
that will not always work. if you have spaces in the rows like

1
2
3
6
8
9

it will only turn out 6 rows and your id will be 9


edit: sorry did see you said no breaks :)