|
-
May 13th, 2002, 03:46 AM
#1
Thread Starter
Hyperactive Member
Last record
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.
-
May 13th, 2002, 09:39 AM
#2
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.
-
May 13th, 2002, 09:42 AM
#3
PowerPoster
you can also append LIMIT to the end of that so it only returns 1 record
PHP Code:
$Sql = "select * from $TableName order by ID DESC LIMIT 1";
-
May 13th, 2002, 11:12 AM
#4
Stuck in the 80s
or, to get the last id (if they're in order with no breaks), do:
PHP Code:
$num = mysql_num_rows(mysql_query("SELECT * FROM $TableName"));
$sql = "SELECT $TableName WHERE ID='$num'";
-
May 13th, 2002, 11:46 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|