Jump to content

Problem finding agenda events of a certain month/year


uss_pt

Recommended Posts

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

 

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

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')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.