Here I am spoofing your result set from your table(s) as a PHP multi array called $rows.
PHP Code:
$rows = array(
0 => array(
'name'=>'Mark',
'city'=>'Chicago',
'date'=>'2012-11-25'
),
1 => array(
'name'=>'John',
'city'=>'New York',
'date'=>'2012-11-25'
),
2 => array(
'name'=>'Jane',
'city'=>'New York',
'date'=>'2012-11-25'
),
3 => array(
'name'=>'Lisa',
'city'=> 'Dallas',
'date'=>'2012-11-26'
),
);
Here's how you'd loop through that result set outputting a bold line every time it got to a new date, or city, with comments you can remove if you like.
PHP Code:
// set 2 temp vars
$last_date = "";
$last_city = "";
// go through the results
foreach ($rows as $row){
// only show date if its a new one
if( $row['date'] !== $last_date)
echo '<b>' . $row['date'] . '</b><br />';
$last_date = $row['date']; // update the var
// only show city if its a new one
if( $row['city'] !== $last_city)
echo '<b>' . $row['city'] . '</b><br />';
$last_city = $row['city']; // update the var
// always echo the name
echo $row['name'] . '<br />';
}
Gives:
2012-11-25
Chicago
Mark
New York
John
Jane
2012-11-26
Dallas
Lisa
Bookmarks