Re: Group By problem

From: Date: Mon, 13 Aug 2001 15:12:17 +0000
Subject: Re: Group By problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11294@lists.php.net to get a copy of this message
"Sharif Islam" <mislam@uillinois.edu> wrote in message news:20010813142719.91341.qmail@pb1.pair.com... > I am trying to caregorize to group at the same time, but its not working. > Any hints? > Here's my code: > $temp="Dummy"; > while ($row = mysql_fetch_array($result)) > { > if($temp !=$row["group_name"]){ > $temp=$row["group_name"] ; > echo "<b>Group:$temp<br></b>"; > > } > > $temp1="blah"; > if($temp1 !=$row["service_cat"]){ > $temp1=$row["service_cat"]; > echo "Services:$temp1<br>"; > } > $machine_name=$row["machine_name"]; > echo "<a > href=view_server.php?machine_name=$machine_name>$machine_name</a><br>"; > } > > This is displaying : > Group:Group_Name > Services:Email > Machine_Name > Services:Email > Machine_name2 > Services: Backup > Machine_name > Group:Group_name2 > ....... > I dont want to print services multiple times. Just like the group name > catagorize it. You don't show your SQL, but I assume it's something like SELECT grp,svc,mach FROM table ORDER BY grp,svc,mach then $grp=""; $svc=""; $firstmach = true; while ($row=mysql_fetch_array($result)) { if ($grp != $row["grp"]) { $grp = $row["grp"]; PrintNewGroup($grp); $svc = ""; // force new-svc when switching groups } if($svc != $row["svc"]) { $svc = $row["svc"]; PrintNewService($svc); $firstmach = true; } PrintMach($row["mach"], $firstmach); $firstmach = false; } Hope this helps...

« previous php.db (#11294) next »