jjmusicpro Posted June 6, 2008 Share Posted June 6, 2008 I am trying to make a news page, where it will show archived news items, and the last 3 news items. I wanted to do a query to get last 10, display 7 of those with just name/title and date, then the other three, with name/title date and info. I can do it in 2 querys thats fine, i just dont know how to get the last 20 records, then -3 from it. Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/ Share on other sites More sharing options...
raku Posted June 6, 2008 Share Posted June 6, 2008 You can try querying to get the total number of rows. Then use LIMIT and OFFSET to choose the last 17. Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/#findComment-559525 Share on other sites More sharing options...
hansford Posted June 6, 2008 Share Posted June 6, 2008 $count = 0; while($row = mysql_fetch_array($result)) { if($count < 7){ echo $row['name'] . " " . $row['title'] . " " . $row['date']; } else{ echo $row['name'] . " " . $row['title'] . " " . $row['date'] . " " . $row['info']; $count = 0; } count++; } Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/#findComment-559526 Share on other sites More sharing options...
jjmusicpro Posted June 6, 2008 Author Share Posted June 6, 2008 so in my sql query i can have something like this? select * from newitems ORDER BY ID DESC LIMIT 25 OFFSET -3 Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/#findComment-559541 Share on other sites More sharing options...
jjmusicpro Posted June 6, 2008 Author Share Posted June 6, 2008 hey that worked thanks! Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/#findComment-559543 Share on other sites More sharing options...
eRott Posted June 6, 2008 Share Posted June 6, 2008 Do not forget to mark the topic as solved. You will find the button on the bottom left of the page. Take care. Quote Link to comment https://forums.phpfreaks.com/topic/109062-solved-how-to-get-last-20-records-from-db/#findComment-559544 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.