I fixed this problem, but now another issue.
I am getting the output liek this
Group
Sevice1
Service2
Machine1
Machine2
I want it like this
Group
Service1
Machine1
Service2
Machine2
And its duplicating the output too.
<?php
$usr="usr";
$pwd="pwd";
$db="database";
$host="localhost";
$conn = mysql_connect("$host", "$usr", "$pwd");
?>
<?php
function getAssocArray($query,$db) {
$res = mysql_db_query($db,$query);
$arr = array();
while ($row = mysql_fetch_array($res)){
$arr[$row["ind"]][] = $row["val"];
}
return $arr;
}
$svr = getAssocArray("SELECT services.group_name AS ind,
service_index.machine_name AS val FROM
services,service_index where
services.service_cat=service_index.service_cat",$db);
$svc = getAssocArray("SELECT services.group_name AS
ind,services.service_cat as val FROM
services",$db);
$keys = array_merge(array_keys($svr), array_keys($svc));
echo "<ul>";
foreach($keys as $ind) {
// group name
echo "<h3>\n\t<br>$ind</b><br></h3>";
// list services
echo "<li>\t<div class='service'>\n\t\t\t".implode(" <br>",$svc[$ind])."\n\t\t</div>";
//echo "<br>$svc[$val]";
// list servers
echo "\n\t\t<div class='machine'>".implode("<br>",$svr[$ind])."\n\t\t</div>";
//echo "<br>$svr[$ind]";
echo "</li>";
}
echo "</ul>";
?>