| | |
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 |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





