Jump to content

Recommended Posts

Hi, I'm stuck, im my table im logging the date (using time()), theirfore contains the column, date (which contains a timestamp).

 

However I'd like to know how to display content from that table based on this week (weekly)?, and another based on today (daily)?. Im thinking I'd need to perhaps manipulate the date column.

 

Heres my code so you can get an understanding of my structure:

 

<?php

//Weekly 10
$result = mysql_query("SELECT * FROM site_reviews ORDER BY date DESC LIMIT 10");

while ($row = mysql_fetch_array($result)){

echo $row['date']."<br>";

echo $row['review'];

}

//Daily 5
$result = mysql_query("SELECT * FROM site_reviews ORDER BY date DESC LIMIT 5");

while ($row = mysql_fetch_array($result)){

echo $row['date']."<br>";

echo $row['review'];

}

?>

 

 

Appreciate any help.  :-\

You can do date comparisons in MySQL.

SELECT * FROM site_reviews ORDER BY date DESC LIMIT 10

Would need a WHERE clause as:

WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= date

 

or for timestamps:

 

WHERE date > (NOW() - 604800)

 

And you would just divide the constants by 7 to get the appropriate daily.

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.