Jump to content

[SOLVED] How to maintain only the 5 latest articles on a page?


pets2soul

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.