Jump to content

[SOLVED] Show mysql Data for only Five days


irkevin

Recommended Posts

Hi,

 

I'm stuck with this now.

 

I have a field in my table call date_added

 

I want to retrieve data from the latest date added and output it for only 5 days on a page.

 

I can't figure out how to do this.

 

Can someone please explain how to proceed?

 

My query look like this:

 

SELECT * FROM tableName  ORDER BY date_added ASC

 

But then, i Don't have a clue how to proceed with this date thing :s

Link to comment
Share on other sites

Create a variable $todays_date, and another variable $five_days_later. Then you can change your query to:

SELECT * FROM tableName  WHERE date_added >= '$todays_date' AND date_added <= '$five_days_later' ORDER BY date_added ASC

 

You can use mktime() to set $five_days_later

Link to comment
Share on other sites

Thats perfect. Exactly what i needed. Thanks bro

 

Below is the code. for those who might need it

 

$make_date = mktime(0,0,0,date("m"),date("d")+5,date("Y"));
$remove_after = date('Y-m-d',$make_date);
$today = strftime('%Y-%m-%d');

"SELECT * FROM tableName WHERE date_added >= '$today' AND date_added <= '$remove_after' ORDER BY date_added ASC"

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.