irkevin Posted August 25, 2009 Share Posted August 25, 2009 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 https://forums.phpfreaks.com/topic/171766-solved-show-mysql-data-for-only-five-days/ Share on other sites More sharing options...
deansatch Posted August 25, 2009 Share Posted August 25, 2009 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 https://forums.phpfreaks.com/topic/171766-solved-show-mysql-data-for-only-five-days/#findComment-905729 Share on other sites More sharing options...
irkevin Posted August 25, 2009 Author Share Posted August 25, 2009 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 https://forums.phpfreaks.com/topic/171766-solved-show-mysql-data-for-only-five-days/#findComment-905739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.