In Drupal 6, how to display two grouping fields such as Country then Province? In Drupal 6, I have a view for certain objects with Location:Country and Location:Province fields, both set to Exclude From Display; sort criteria to sort first by country then by province; and Style setting Grouping Field to be Location:Province. That displays all the objects in the order I want, everything with the same country grouped together, then within each country objects are grouped by Province/State, each state's group of objects labelled with the name of the state.

However, I would like to have a group title displayed for Country, not just Province, so it would look like

Canada
  Ontario
    object 1
    object 2
  Quebec
    object 3
United States
  Arizona
    object 4
  California
    object 5
    object 6


I'm a newbie to Drupal. Is there a standard way to do this? I've tried search terms such as nested grouping and multiple groups but haven't found mention of this use case.
If you are comfortable with theme templates, you could do this by modifying the Style output, eg:



for your View.  Here I created a quick View called for-da-grouping like this:



which has the node title and then two fields, country and province which are excluded from display.  I am sorting first on Country and then within that Province, so, given the same information in your example, this produces:



But, if you add some logic to your new Views template:

&lt;?php
/**
 * @file views-view-unformatted.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */

$country='';
$province='';

/*
  drupal_set_message('&lt;pre&gt;' . print_r($view-&gt;result[0], TRUE) . '&lt;/pre&gt;');

    [node_title] =&gt; object 1
    [nid] =&gt; 660
    [node_language] =&gt; 
    [node_data_field_da_country_field_da_country_value] =&gt; Canada
    [node_type] =&gt; page
    [node_vid] =&gt; 660
    [node_data_field_da_country_field_da_province_value] =&gt; Ontario

*/

?&gt;
&lt;?php if (!empty($title)): ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;?php if ($view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_country_value!=$country): ?&gt;
    &lt;div class="country-group-title"&gt;
      &lt;?php print check_plain($view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_country_value); ?&gt;
      &lt;?php $country=$view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_country_value; ?&gt;
    &lt;/div&gt;
  &lt;?php endif; ?&gt;
  &lt;?php if ($view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_province_value!=$province): ?&gt;
    &lt;div class="province-group-title"&gt;
      &lt;?php print check_plain($view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_province_value); ?&gt;
      &lt;?php $province=$view-&gt;result[$id]-&gt;node_data_field_da_country_field_da_province_value; ?&gt;
    &lt;/div&gt;
  &lt;?php endif; ?&gt;
  &lt;div class="&lt;?php print $classes[$id]; ?&gt;"&gt;
    &lt;?php print $row; ?&gt;
  &lt;/div&gt;
&lt;?php endforeach; ?&gt;


You can get:



Now, things to look at in specific:


You need to sort your View first by country and then by province so the data is in the right order to begin with.
You need to know your Views results, they are stored in $view-&gt;result and you can get what you need out of looking at $view-&gt;result[0] and in my view, my two fields I want to group on are called node_data_field_da_country_field_da_country_value and node_data_field_da_country_field_da_province_value  but yours are most probably going to be different but the logic is still the same:  Only display the country and/or province if it has changed since the last time it was displayed.
Add some css to your new group headings and you should be all set.


If not, you can investigate the Views Field Module and so forth mentioned in https://stackoverflow.com/questions/9015500/how-to-group-by-more-than-one-field-in-drupal-view for alternative methods.