| | |
Displaying News Articles
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I've been thinking for awhile now that I should code a nice news system, and I have the structure all figured out, but what stumped me was: How do you display the articles with the latest first?
I would set up a MySQL table with columns Title, Date&Time, Body, ID, Author, Source (not in that order). How would I then go about retrieving them and listing them in reverse order?
I would set up a MySQL table with columns Title, Date&Time, Body, ID, Author, Source (not in that order). How would I then go about retrieving them and listing them in reverse order?
Geek and a Half Blog
Use ORDER BY command in your database query.
If you not sure about SQL commands, do your search on google or yahoo.
If you not sure about SQL commands, do your search on google or yahoo.
Ecommerce-Web-Store.com Building Your e-Business.
This is the query I use on my CMS system:
[PHP]$query="SELECT * FROM news ORDER BY id DESC LIMIT 5";[/PHP]
ORDER BY id DESC will get the latest article first (the article with the highest id).
LIMIT 5 is a useful thing - it gets only the amount of articles you specify. If you didn't have this, all your articles would show on one page, and if there are lots of posts, you will end up with a massive page.
[PHP]$query="SELECT * FROM news ORDER BY id DESC LIMIT 5";[/PHP]
ORDER BY id DESC will get the latest article first (the article with the highest id).
LIMIT 5 is a useful thing - it gets only the amount of articles you specify. If you didn't have this, all your articles would show on one page, and if there are lots of posts, you will end up with a massive page.
![]() |
Similar Threads
- need help finding a script or tool to use for a news update program. (PHP)
- Complex Question: Saving large articles to the DB (Perl)
- iexplorer.exe error and restarting after going to some websites (Web Browsers)
- News put in the forums (Growing an Online Community)
- Latest News or Even old news gets updated on the site? Where to get the news articles (Existing Scripts)
- Suggestions for my web hosting news site? (Growing an Online Community)
Other Threads in the PHP Forum
- Previous Thread: Arrays
- Next Thread: Generating .doc reports
| Thread Tools | Search this Thread |
address apache api array auto autoincrement beginner binary broken cache cakephp checkbox class cms code cron curl customizableitems database date dehasher display dynamic echo email error errorlog external file files folder form format forms forum function functions gc_maxlifetime google headmethod host href htaccess html image include incode insert ip javascript joomla limit link login mail malfunctioning masterthesis menu method mlm multiple mysql oop parsing paypal pdf php phpmysql popup problem query question radio random recursion remote script search select server sessions sms source space sql support! survey syntax system table trouble tutorial update upload url validator variable video web youtube





