Lassie Posted January 6, 2014 Share Posted January 6, 2014 I am developing a calendar for use on a wordpress site. I have a series of events and need to retrieve all the events in a selected month and get them into the $events array I am getting no results from my query and no errors. My table has title, event_date,time.notes,post code. Only the first two fields are populated at the moment The event_date is stored as DATE. After retrieving the data $year,$month and $events is passed to a function to draw the calendar and show the months events. $events = array(); global $wpdb; $query=("SELECT title, DATE_FORMAT(event_date,'%Y-%m-%D')FROM sw_appointments WHERE event_date LIKE '$year-$month%'"); $result = $wpdb->get_results($query); print_r($result); while($row = mysql_fetch_assoc($result)) { $events[$row['event_date']][] = $row; /* verify that the query gets results. Also generates a list of this months events */ echo $row['title']." ----- ".$row['event_date']; echo "<br />"; } Any suggestions appreciated Link to comment https://forums.phpfreaks.com/topic/285144-retrieve-date-with-query/ Share on other sites More sharing options...
Barand Posted January 6, 2014 Share Posted January 6, 2014 You need to echo the query and see what is being run. I suspect you could be searching for dates where LIKE '2014-1' Instead try ... WHERE YEAR(event_date) = $year AND MONTH(event_date) = $month Link to comment https://forums.phpfreaks.com/topic/285144-retrieve-date-with-query/#findComment-1464101 Share on other sites More sharing options...
Lassie Posted January 6, 2014 Author Share Posted January 6, 2014 Thanks for that. It works and it was LIKE 2014-1 Link to comment https://forums.phpfreaks.com/topic/285144-retrieve-date-with-query/#findComment-1464104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.