
August 22nd, 2008, 03:56 PM
|
|
Me
|
|
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937

Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
|
|
in all honesty, I was just working on it and couldn't get it it to display properly without some major changes and that even had a mistake with the count not working without setting another variable containing the count from the last loop and more. I would actually suggest re-writing it so the query results are put into a multi-dimensional array and loop through those results for displaying them out.
something kinda like:
PHP Code:
<?php
$q1 = "SELECT *, (SELECT COUNT(*) FROM TableName AS t2 WHERE `Name`=`TableName`.`Name`) AS `count` FROM TableName WHERE (".$criteria.") ORDER BY `count`, `Name`, `Criteria`";
while($a1 = mysql_fetch_array($r1)){
//put all the results into a multi-dimensional array.
$results[$a1['Name']][] = $a1['Criteria'];
}
$n = 0;
//loop through the outter array.
foreach($results as $Name=>$value){
$n++;
echo<<<HTML
<tr>
<td valign="top">
<script language="JavaScript">
expanded[{$n}] = 0
</script>
HTML;
echo " <img src=\"Images/" . (($expanded[$n] == 0) ? "plus" : "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\"> {$Name}\n";
echo " <div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" : "") . "\">\n";
//loop through each criteria
foreach($value as $Criteria){
echo " {$Criteria}\n";
}
echo " </div>\n";
echo " </td>\n";
echo " <td align=\"center\" valign=\"top\">\n";
echo " ".count($value);
echo " </td>\n </tr>\n";
}
That should do everything your script does and it was definately easier to write.
And if you look at the source of the code you originally had it was improper and wasn't well formed. This is complete and valid and is even formatted with spaces and such to make the source look readable.
Last edited by IAmALlama : August 22nd, 2008 at 04:00 PM.
|