I am struggling with displaying a query and I could use some help. Any
direction or advice would be greatly appreciated.

I have a query that returns 3 fields, name, sub_area, and description.
(actually it returns others but these three will be enough to describe.) I
order the query by sub_area, name.

My goal is to list the results in a group for each sub_area. (i.e. $sub_area
has $counter records and they are...)

My attempt at this is to loop though the records several times, once to
create an array of the sub_area and their count, then one loop each for each
sub_area to process the records. This sure seems like a lot of looping
through records! There must be a better way, I think I am just stuck looking
at this from one direction. Your help will be appreciated.

$sub_count = 1;
$array_count = 0;
$last_area = '';

while ($f = db_fetch_object($qid)) {
    $this_area = $f->sub_area;
        if ($last_area == '') {
            $last_area = $this_area;
        } else if ($this_area != $last_area) {
            $area_list[$array_count][0] = "$last_area";
            $area_list[$array_count][1] = "$sub_count";
            $last_area = $this_area;
        } else {

$area_list[$array_count][0] = "$last_area";
$area_list[$array_count][1] = "$sub_count";

foreach (array_keys($area_list) as $bar) {
    print($area_list[$bar][0].' has '.$area_list[$bar][1].', they are:\n');
    while ($r = db_fetch_object($qid)) {
        if ($r->sub_area == $area_list[$bar][0]) {

Thom Dunaway


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to