DrDankWD Posted March 28, 2008 Share Posted March 28, 2008 Hello, I am trying to figure out something for a news module. I would like to display a random news article from the database, but I would like to limit it to the 5 most recent news posts. For instance: There are 25 dated articles in the database, Out of the 5 most recent I would like to pick one to display. I am not sure how to write this query, any help would be much appreciated. Thanks DrDankWD Link to comment https://forums.phpfreaks.com/topic/98397-selecting-a-random-row-from-the-5-most-recent-entries/ Share on other sites More sharing options...
Barand Posted March 28, 2008 Share Posted March 28, 2008 <?php $x = rand(0,4); $sql = "SELECT * FROM news ORDER BY newsdate DESC LIMIT $x, 1"; Link to comment https://forums.phpfreaks.com/topic/98397-selecting-a-random-row-from-the-5-most-recent-entries/#findComment-503539 Share on other sites More sharing options...
DrDankWD Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks a bunch, it worked beautifully. Link to comment https://forums.phpfreaks.com/topic/98397-selecting-a-random-row-from-the-5-most-recent-entries/#findComment-503541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.