uss_pt Posted September 29, 2009 Share Posted September 29, 2009 Hi there! I've a table for events with the following structure TABLE events id date_begin date_end I'm having problems to find a query that can list me the events for a certain month/year ex: i want to call a php function with params (month, year) to obtain the matched events getEventsByMonth($month,$year) thx in advance Link to comment https://forums.phpfreaks.com/topic/175936-problem-finding-agenda-events-of-a-certain-monthyear/ Share on other sites More sharing options...
uss_pt Posted September 29, 2009 Author Share Posted September 29, 2009 MySql 5.0.67-community; PHP version-5.2.9 The current query i have is $query = "SELECT * FROM eventos WHERE status='0' AND MONTH(date_begin)<='$month' AND YEAR(date_end)<='$year' AND MONTH(date_begin)>='$month' AND YEAR(date_end)>='$year'"; but it doesn't work for all the cases Link to comment https://forums.phpfreaks.com/topic/175936-problem-finding-agenda-events-of-a-certain-monthyear/#findComment-927131 Share on other sites More sharing options...
fenway Posted October 5, 2009 Share Posted October 5, 2009 Define "problem". Link to comment https://forums.phpfreaks.com/topic/175936-problem-finding-agenda-events-of-a-certain-monthyear/#findComment-930762 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 If your trying to list events for a specific MONTH and YEAR, why are you checking if the month of the date_begin is before or equal to and after or equal to, shouldn't you just be checking if it's equal? If I was to hazard a guess based on your description I'd have thought your after. $query = " SELECT * FROM eventos WHERE status='0' AND (MONTH(date_begin)='$month' OR MONTH(date_end)='$month') AND (YEAR(date_begin)='$year' OR YEAR(date_end)='$year')"; Link to comment https://forums.phpfreaks.com/topic/175936-problem-finding-agenda-events-of-a-certain-monthyear/#findComment-930856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.