jalmz Posted April 13, 2011 Share Posted April 13, 2011 Hi guys, Im having problem on how to achieved this one.. I would like to get the all event of this month (April ) Starting todays date.. $now = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+8, gmdate("Y"))); $week = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+30, gmdate("Y"))); if ($result = mysql_query("SELECT * FROM fiesta WHERE sta_date BETWEEN '$now' AND '$week' ORDER BY sta_date LIMIT 10")){ if (mysql_num_rows($result)) { $return = ''; while ($row = mysql_fetch_array( $result )) { $date = date("D",strtotime($row["sta_date"])); $return .= "<a href='sta.php' style='font-size:11px;' title='" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> ($date), "; } echo rtrim($return, ', '); } } The result of this query will include the events on May.. How can i display only the event on this month(April)? starting todays date. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/ Share on other sites More sharing options...
JonnoTheDev Posted April 13, 2011 Share Posted April 13, 2011 Forget all the php date functions. Use MYSQL functions! I hope that the sta_date field in your database is of DATE type SELECT * FROM fiesta WHERE MONTH(sta_date) = MONTH(CURDATE()) AND YEAR(sta_date) = YEAR(CURDATE()) AND DAY(sta_date) >= DAY(CURDATE()) ORDER BY sta_date The above will give you all records of the current month & year that are on or in future of todays date. Test the query out before using it in your php code. Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/#findComment-1201036 Share on other sites More sharing options...
jalmz Posted April 13, 2011 Author Share Posted April 13, 2011 Thanks for the reply it works perfectly.. what about today's date + 7. For example today is April 13, 2011. I will display the event beginning on April 20 to the end of this month.. thank you Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/#findComment-1201061 Share on other sites More sharing options...
JonnoTheDev Posted April 13, 2011 Share Posted April 13, 2011 Thanks for the reply it works perfectly.. what about today's date + 7. SELECT * FROM fiesta WHERE MONTH(sta_date) = MONTH(CURDATE()) AND YEAR(sta_date) = YEAR(CURDATE()) AND DAY(sta_date) >= DAY(DATE_ADD(CURDATE(),INTERVAL 7 DAY)) ORDER BY sta_date Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/#findComment-1201150 Share on other sites More sharing options...
jalmz Posted April 13, 2011 Author Share Posted April 13, 2011 wow.. Thank you neil.. just one last question.. what about this code... that uses Unix Time Stamp? $time_now = time(); $week = $time_now + 86400; $time_tom = $time_now + 518400; if ($result = mysql_query ("SELECT dateline, dateline_from, eventid, title FROM vb_event WHERE calendarid = 1 AND dateline_from BETWEEN '$week' AND '$time_tom' ORDER BY dateline_from LIMIT 7")) { if (mysql_num_rows($result)) { $return = ''; while ($row = mysql_fetch_array( $result )) { $return .= "<a href='/forum/calendar.php?do=getinfo&e=" . $row['eventid'] . "&c=1' title='". $row['title'] . "' style='font-size:11px;'>" . $row['title'] . "</a> (". date("D", $row['dateline_from']+54000)."), "; } echo rtrim($return, ', '); } else { echo "No events currently listed"; } } The result of this code is todays date + 3 days.. How can I display Todays Date + 7 days For this Month of April. Again, thank you Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/#findComment-1201324 Share on other sites More sharing options...
jalmz Posted April 15, 2011 Author Share Posted April 15, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/233574-php-mysql-fetch-the-events-of-this-month/#findComment-1201837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.