86Stang Posted February 9, 2010 Share Posted February 9, 2010 I've got the following two tables: EVENTS ------------------- event_id title info DATES ------------------- id event_date event_id and I'm pulling the data I need via this query: $qry = "SELECT id,event_date,title,events.event_id FROM events INNER JOIN dates ON dates.event_id = events.event_id ORDER BY event_date asc"; Using a WHILE loop off of that query, I can get that query to generate something akin to: 2010-02-07 Title 1 2010-02-09 Title 2 2010-02-09 Title 3 2010-02-09 Title 4 2010-02-11 Title 5 2010-02-12 Title 6 but what I need is a loop that will show each date only once with the info below it, like: 2010-02-07 Title 1 2010-02-09 Title 2 Title 3 Title 4 2010-02-11 Title 5 2010-02-12 Title 6 I'm sure this is a quick kill for a lot of you out there so I'm hoping a kind soul can help me out. Link to comment https://forums.phpfreaks.com/topic/191551-help-building-the-proper-loop/ Share on other sites More sharing options...
Psycho Posted February 9, 2010 Share Posted February 9, 2010 $output = ''; $current_date = ''; while($record = mysql_fetch_assoc($result)) { //Display date ONLY IF NEW if ($current_date != $record['event_date']) { $current_date = $record['event_date']; $output .= "<b>{$current_date}</b><br>\n"; } $output .= "{$record['title']}<br>\n"; } echo $output; Link to comment https://forums.phpfreaks.com/topic/191551-help-building-the-proper-loop/#findComment-1009752 Share on other sites More sharing options...
86Stang Posted February 9, 2010 Author Share Posted February 9, 2010 That is SOOO simple! Mucho gracious!! Link to comment https://forums.phpfreaks.com/topic/191551-help-building-the-proper-loop/#findComment-1009763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.