c-o-d-e Posted December 4, 2009 Share Posted December 4, 2009 Hello, I'm working on a recent news section. To post a news article on my website, on the Admin Control Panel will have a section which has.. an 2 fields. Article Name - textbox Article - textarea Then the submit button, what I am guessing.. you'll post the article, and it'll go into a database table with 3 collums. ID - Article Name - Article - Time Submitted With this table, on every page on my website, will have the recent news section. In that section .. the limit of news will be 3. So.. in a query - LIMIT 3. Time and date that will be posted in the "Time Submitted", which I understand it will be inserted as "time()" into the DB. It should be displayed like this.. in the Recent News section on each page; [b]my article[/b] [b]04/12/09 - 4:47PM[/b] News here News here News here [b]my article[/b] [b]05/12/09 - 1:00PM[/b] news here news here news here Etc etc. On the "All Updates" page, will display ALL the updates, will will be paginated, which I can do, which will be formatted like the above too, with the most recent first, to the latest last. Any idea on how the Queries would look like. I have a rough idea, but I'm not sure how I'd set it for the Recent News section to be the most recent first. Which would be the same for both queries, just one with LIMIT 3. $query = mysql_query("SELECT * FROM News ORDER BY (Something to order with most recent first) LIMIT 3") or trigger_error etc etc $row = mysql_fetch_array($query); $time //Ill turn the timestamp in the database to a date setting echo '<strong>'. $row['articlename'] .'<br />'. $time .'</strong><br />'. $row['article'] .'' It'd be similar to the whole updates page, just without LIMIT 3. Is this right? Can you give me in depth information on how to do what I'd like to do. Quote Link to comment https://forums.phpfreaks.com/topic/184004-in-depth-how-would-i-do-an-recent-news-section/ Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 Order by the date? Quote Link to comment https://forums.phpfreaks.com/topic/184004-in-depth-how-would-i-do-an-recent-news-section/#findComment-971415 Share on other sites More sharing options...
c-o-d-e Posted December 4, 2009 Author Share Posted December 4, 2009 Would what I said be the best way? Order by.. yeah it'll be date, but how would that show the most recent, or the latest? Quote Link to comment https://forums.phpfreaks.com/topic/184004-in-depth-how-would-i-do-an-recent-news-section/#findComment-971471 Share on other sites More sharing options...
raytri Posted December 4, 2009 Share Posted December 4, 2009 Use the "DESC" modifier. It sorts the selected column from highest number (most recent time, in this case) to lowest. $query = mysql_query("SELECT * FROM News ORDER BY TimeSubmitted DESC LIMIT 3") Quote Link to comment https://forums.phpfreaks.com/topic/184004-in-depth-how-would-i-do-an-recent-news-section/#findComment-971549 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.