tags:

views:

78

answers:

1

I want to pull out the records that have a date that is LIKE today's date.

I have this query

$query = "select * from calendar_items WHERE expiredate LIKE '$todays_date %' 
    or upcoming_event_featured_date like '$todays_date %' 
    ORDER BY expiredate ASC";

Now I have 3 more upcoming_event_featured_date's: upcoming_event_featured_date2, upcoming_event_featured_date3, upcoming_event_featured_date4

So I want to run a query that will grab the results that has a date LIKE that of the four upcoming_event_featured_date's (upcoming_event_featured_date, upcoming_event_featured_date2, upcoming_event_featured_date3, upcoming_event_featured_date4).

Would the query look something like this?

$query = "select * from calendar_items 
    WHERE expiredate LIKE '$todays_date %' or 
    (upcoming_event_featured_date like '$todays_date %' or 
    upcoming_event_featured_date2 like '$todays_date %' or 
    upcoming_event_featured_date3 like '$todays_date %' or 
    upcoming_event_featured_date4 like '$todays_date %') 
    ORDER BY expiredate ASC";
+1  A: 

You should definitely listen to HLGEM and normalize the table structure. But for what you're asking for, that query will likely work assuming $todays_date is an actual date (like 2009-11-16). You may need to move the % closer, though, to be a bit safer:

$query = "select * from calendar_items 
WHERE expiredate LIKE '{$todays_date}%' or 
(upcoming_event_featured_date like '{$todays_date}%' or 
upcoming_event_featured_date2 like '{$todays_date}%' or 
upcoming_event_featured_date3 like '{$todays_date}%' or 
upcoming_event_featured_date4 like '{$todays_date}%') 
ORDER BY expiredate ASC";
Chris