Jump to content

Selecting records based on date


poleposters

Recommended Posts

Hi,

 

I'm wrting a blog script. Alongside each blog entry I want to display links to 5 other entries which are closest to the date of the current entry.

 

ie, if the entry being viewed is for the 18th of January. I want to display the five previous entries.13th,14th,15th,16th and 17th of January.

 

Is this possible? can someone point me in the right direction?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/167369-selecting-records-based-on-date/
Share on other sites

You can use row identifiers and a simple WHERE clause:

 

SELECT * FROM entries WHERE id < 10 LIMIT 5

 

In the WHERE clause, you put the ID of the current row - the identifiers are incrementing with each new entry, so they represent the entries in the chronological order, too. If for some reason this cannot be used, you can simply replace "id" with entry date, and this will also work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.