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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Solution Lassie Posted January 6, 2014 Author Solution Share Posted January 6, 2014 Thanks for that. It works and it was LIKE 2014-1 Quote Link to comment 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.