I'm building a scheduler, something along the lines of Google Calendar, where a user can input events and generally plan their day. One of the features I wish to add is a check for time clashing, where if two events overlap a small image alert will display. What I currently have is like so: 1) query db and loop thru results 2) for each and every event, query db again and look for clashes 3) if there are clashes, add image to $output 4) echo $output The actual problem is the query within a loop, which is an awful example of coding, I know. Is there some kind of... uh, funky recursive loop or something... that I can use? Any advise appreciated. This is the actual code, if anyone's interested: [code] <?php // sort of pseudo code // Get all events happening in a day. // For each event check if another event clashes with it, then output. $query = "SELECT * FROM events WHERE date='$today'"; $result = mysql_query($query) or die ("Query failed: " . mysql_error()); if ($myrow = mysql_fetch_array($result)) { do { $this_id = $myrow['id']; $ts = $myrow['timestart']; $te = $myrow['timeend']; $query2 = "SELECT id,timestart,timeend FROM events WHERE date='$today' AND id<>$this_id"; $result2 = mysql_query($query2) or die ("Query failed: " . mysql_error()); while ($myrow2 = mysql_fetch_array($result2)) { $ts2 = $myrow['timestart']; $te2 = $myrow['timeend']; // if event2 starts and ends totally before or after event1, then no clash if ( ($te2<=$ts) || ($ts2>=$te) ) { // no clash } else { // clash! $clash[$j] = $myrow['id']; $j++; } } if ($j>0) $clash = '<img src="clash.gif">'; echo $clash.' event details here'; // output event details } while ($myrow = mysql_fetch_array($result)); } ?> [/code] Edit: Edited for clarity.