Jump to content

Last db items?


Kyle123

Recommended Posts

What he said. But, you will need a field to use for ordering the records to achieve this. If there is an auto-incrementing ID field you can use that. Otherwise you would probably want to create a timestamp field that is automatically populated when the record is created. If you have an existing field of either type you can use that. If not, you can add either one such that you wouldn't have to change any of your existing code since they would be handled automatically by the database.

 

The query to get what you need would look something like this

SELECT field1, field2, field3
FROM table_name
ORDER BY order_field DESC
LIMIT 5

 

Where 'order_field' is the auto-incrementing int or timestamp field.

Link to comment
https://forums.phpfreaks.com/topic/258053-last-db-items/#findComment-1322795
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.