Results 1 to 5 of 5

Thread: Last record

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    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.

  2. #2
    scoutt
    Guest
    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.

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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"

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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'"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width