There is another way, which takes a bit more setting up when you're grabbing the data, but makes the output to HTML neater.
You can create a hash (associative array) where the key is the field that you're grouping by:-
---------------------------- code ------------------------------------
$result = mysql_query("select boss,country from table order by country");
$data=array();
while ($row = mysql_fetch_array($result)){
// get the group for this row
$group = $row["country"];
// create a key for it if we haven't seen it before
if (!$data[$group]) $data[$group]=array();
// put the data into the array under the key for this group
array_push($data[$group], $row);
}
So you've now got a data structure which looks like (pseudocode):-
$data["uk"] = array("tony", "david", "estelle")
$data["usa"] = array("george", "donald", "colin")
$data["france"] = array("chirac?", "le pen?")
... which you can now output like this:-
---------------------------- code ------------------------------------
foreach($data as $group) {
// heading
printf("<h4>%s</h4>", $group[0]["country"]);
// contents of the group
foreach ($group as $row) {
printf("%s<br>", $row["boss"]);
}
}
Hope this helps
Tom