pets2soul Posted June 20, 2008 Share Posted June 20, 2008 Hello everyone! I'm new to the PHP world, I'm trying to make a news archive type of web page. So far, I've done making an admin page, where I can submit articles to a MySQL database, I know how to have all the stored articles to be shown on one page, however, I don't know how to have only the latest 5 to be shown... ??? ??? The columns I have in my database are article title, article body and entry date. Would anyone give me some guidance? Appreciate! Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/ Share on other sites More sharing options...
Vizor Posted June 20, 2008 Share Posted June 20, 2008 How is the date column set up? is it a timestamp value? if it is then you can just do SELECT * FROM articles ORDER BY date DESC LIMIT 5; Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-570007 Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 and if you want to show it in different pages, each contains 5 articles, $pageno=$_GET['pageno']; $sql="SELECT * FROM articles ORDER BY date DESC LIMIT 0,".($pageno*5); then link the pages like page.php?pageno=1,page.php?pageno=2 etc. Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-570016 Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 How is the date column set up? is it a timestamp value? if it is then you can just do SELECT * FROM articles ORDER BY date DESC LIMIT 5; what ever format the date column is, whether it is TIMESTAMP, DATE or DATETIME, you can always use this sql query cause SQL can order date irrespective of the format, as long as format is one of the above three. Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-570021 Share on other sites More sharing options...
pets2soul Posted June 25, 2008 Author Share Posted June 25, 2008 Ouch...my question revealed how immature I'm in the PHP world.... Thanks to Vizor and abdbuet, the answers are very helpful!! Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-573955 Share on other sites More sharing options...
pets2soul Posted July 7, 2008 Author Share Posted July 7, 2008 Hello there, The more pages I'm working, more questions popped up...and since this one is similar to this subject, so I'm just posting it here.... What I'm trying to do now on another page, is to show only the article entries from the latest day...this is what I got in mind: $result=mysql_query("SELECT * FROM news WHERE date BETWEEN '2008-01-01' AND '2008-12-31' GROUP BY date ORDER BY fname DESC LIMIT 1"); I have "date" as one of my database column, in the format of yyyy-mm-dd. However, if I set the LIMIT to be 1, only the ONE last entry would be shown, but what do I do if I have more than one entries made in the same day? What I missed in the code? Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583259 Share on other sites More sharing options...
marcus Posted July 7, 2008 Share Posted July 7, 2008 Remove the LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583261 Share on other sites More sharing options...
pets2soul Posted July 7, 2008 Author Share Posted July 7, 2008 and if I do that...all the entries from 2008-01-01 to 2008-12-31 would be shown.... Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583265 Share on other sites More sharing options...
Lodius2000 Posted July 7, 2008 Share Posted July 7, 2008 yes Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583266 Share on other sites More sharing options...
Lodius2000 Posted July 7, 2008 Share Posted July 7, 2008 pets2soul adapt http://hell.org.ua/Docs/oreilly/webprog/pcook/ch10_14.htm that your code and it will give you automatically paginated links that are dynamically created so you dont have to create pages with 5 articles a piece Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583268 Share on other sites More sharing options...
pets2soul Posted July 7, 2008 Author Share Posted July 7, 2008 ahh....sorry that I messed up this topic....I extracted my new question to a new post.... Quote Link to comment https://forums.phpfreaks.com/topic/111077-solved-how-to-maintain-only-the-5-latest-articles-on-a-page/#findComment-583284 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.