huntrguy102 Posted March 8, 2010 Share Posted March 8, 2010 I have a database full of information of books (I.D.#, title, author, genre, publisher). What I need is for the 3 most recent books in the database to be posted on the website. Is there a way to use the I.D. numbers to post the most recent, so I could just add more books and it would update itself to the most recent. They are ordered 1,2,3,4 etc. the highest numbers being the most recent. Any help would be greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/194513-posting-recent-data-from-mysql-database/ Share on other sites More sharing options...
straylight Posted March 8, 2010 Share Posted March 8, 2010 If your book table's primary key is a field called "id", then something like this will do it: SELECT * FROM books ORDER BY id DESC LIMIT 3 With this SQL, the most recent book will be the last one in the results. You could get the most recent book to appear at the top of the results like this: SELECT * FROM ( SELECT * FROM books ORDER BY id DESC LIMIT 3 ) x order by id ASC ; Or you could just loop through it backwards in the PHP Quote Link to comment https://forums.phpfreaks.com/topic/194513-posting-recent-data-from-mysql-database/#findComment-1023227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.