PDA

View Full Version : Displaying an event closest to current date



fastsol1
07-27-2010, 01:48 PM
So I have a Events area on this site and I have it set to LIMIT 3 for events that are within the current date and the event date. These dates are stored in the table with the event info. What I want is even if I have 5 events scheduled on various days but the first date in the table for all of them is the current date and the second date are various days in the future, I want the three events that are closest to the current date to be shown. Here is the query I currently use.


$date = date ("Y-m-d");
$get_event = mysql_query("SELECT *, SUBSTRING(event_para, 1, 150)AS event_para FROM events WHERE date_start<='$date' AND date_end>='$date' LIMIT 3");

I think I would need a different function or something in place of the $date to determine this but I have no idea how to achieve this.

So say event one had a date_start of today and date_end of 8/1/10. Event two had a date_start of today and date_end of 8/16/10. Event three had a date_start of today and date_end of 8/3/10. Event four had a date_start of today and date_end of 9/1/10. Event five had a date_start of today and date_end of 8/15/10. What I want is that events 1, 2, 5 would show since their date_end is the closest to todays date. Hope that is pretty clear. Any help is greatly appreciated.

fastsol1
07-27-2010, 02:26 PM
Ok, nevermind. Maybe I should have thought about this a little better. A simple ORDER BY date_end ASC did it. I was dreaming about all this code last night and confused myself.