How to get the last field in a Mysql database with PHP?

前端 未结 5 1841
故里飘歌
故里飘歌 2020-12-19 13:21

I have mysql database and I want to get the last ID from field in a table .

example : -

id   Value
1    david
2    jone
3    chris

相关标签:
5条回答
  • 2020-12-19 13:53

    you can also use the following code ::

     $lastId = mysql_insert_id();
    
    0 讨论(0)
  • 2020-12-19 13:56

    If you want to select the ID of the most recently inserted row in a table with an AUTO_INCREMENT column, you will likey be interested in MySQL's LAST_INSERT_ID function.

    0 讨论(0)
  • 2020-12-19 13:56
    SELECT * FROM table ORDER BY id DESC LIMIT 1
    
    0 讨论(0)
  • 2020-12-19 14:04

    You can use:

    SELECT MAX(id) FROM table
    
    0 讨论(0)
  • 2020-12-19 14:08
    SELECT id
    FROM table
    ORDER BY id DESC
    LIMIT 1
    
    0 讨论(0)
提交回复
热议问题