On Fri, 5 Apr 2002, Phil Ewington wrote: > This is for an events calendar, I want all the dates form the db but when I > am generating the individual days for the calendar I need to know whether > there is an event for that day, hence pulling out all the dates from the db. > As I am looping through all the days in a month to dynamically create the > calendar, I do not want to loop through the entire recordset to look for a > date for that day in each iteration.
That sounds like a lot of work (both for you and for the server). Assuming you want to draw a monthly calendar where each day appears whether or not it holds any events (it's even easier if you don't need that)... Just make sure the database returns your results in date order. SELECT eventtitle, eventdate FROM event WHERE eventdate>='2002-03-01' AND eventdate<'2002-04-01' ORDER BY eventdate Then loop through the days and draw any events that happen to occur on each day as you get to it: $row = mysql_fetch_assoc($sql); for ($day = 1; $day <= $num_days_in_month; $day++) { print "<h3>$day</h3>"; while ($row && (date('j', strtotime($row['eventdate'])) == $day)) { print "<p>{$row['eventtitle']}</p>"; $row = mysql_fetch_assoc($sql); } } miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php