Jump to content

Select 5 results from 3 days (total of 15 results)


The Little Guy

Recommended Posts

I have a feed that shows the last 3 days, the info comes from a database.

 

$twoDaysAgo = strtotime($cDate." - 2 days");
$query = "SELECT * FROM feed WHERE (`owner` = '3' AND `owner`) AND `feedDate` >= '$twoDaysAgo' ORDER BY `feedDate` DESC, `id` DESC";

 

How can select a limit of 5 for today, yesterday, and the day before (no matter what day it is now)?

I may be misinterpreting your question, but basically you just need to limit your results to only 5?  Just add "LIMIT 5" to the end of the query string:

 

$query = "SELECT * FROM feed WHERE (`owner` = '3' AND `owner`) AND `feedDate` >= '$twoDaysAgo' ORDER BY `feedDate` DESC, `id` DESC LIMIT 5"

I may be misinterpreting your question, but basically you just need to limit your results to only 5?  Just add "LIMIT 5" to the end of the query string:

 

$query = "SELECT * FROM feed WHERE (`owner` = '3' AND `owner`) AND `feedDate` >= '$twoDaysAgo' ORDER BY `feedDate` DESC, `id` DESC LIMIT 5"

 

or set up 3 different select queries one for each day and set each ones limit to 5 if you are looking for five from each day.

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.