Guest tantrum_jon Posted April 9, 2007 Share Posted April 9, 2007 Greetings. I am attempting to display information from a table within a MySQL database, but I am having a problem with how to write the line to show only what I want. I am a beginner/intermediate coder and I'm still learning. Here is what I am attempting. I have a database that will display news and events. I want to display the news/event title, content and the date of the post. That is not my problem, pulling that from the database and showing it is particularly easy. My problem, is I only want to show the 5 newest news and/or events for example. I am aware that the text WHERE ID = 1 or WHERE ID = >5 can be used, but what would I used to show the newest posts? I want to show 5 posts, and as I add a new post, I want the oldest to not be displayed, and the newest to be added to the top of the listing. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/46354-solved-displaying-table-content-question/ Share on other sites More sharing options...
pikemsu28 Posted April 10, 2007 Share Posted April 10, 2007 if i were doing this i would select all my records and order them by ID Descending and limit to 5 something like: $sql = "select * from (table_name) order by id desc limit 5"; Link to comment https://forums.phpfreaks.com/topic/46354-solved-displaying-table-content-question/#findComment-226010 Share on other sites More sharing options...
Guest tantrum_jon Posted April 10, 2007 Share Posted April 10, 2007 Thank you. Link to comment https://forums.phpfreaks.com/topic/46354-solved-displaying-table-content-question/#findComment-226116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.