My SQL query is:
Code: Select all
SELECT rop1, AffinityBloc, rop2, PeopleCluster, rop3, PeopNameAcrossCountries, rog3, Ctry FROM jppeoples ORDER BY AffinityBloc, PeopleCluster, PeopNameAcrossCountries, Ctryhttp://www.pysquared.com/sqloutput.jpg
Which returns about 16,000 records. I need to output it in nested ul lists to make the page like the example above. This kind of thing hurts my head, but I think I need like some nested if statements comparing
There are 4 levels. Affinity Block, People Cluster, People Group Name, and finally the Country. Here is something like the code I have so far, but I am just not going far enough I guess, can someone help me out with this, or perhaps know a simpler way to do this.
Code: Select all
$sql = "SELECT rop1, AffinityBloc, rop2, PeopleCluster, rop3, PeopNameAcrossCountries, rog3, Ctry FROM jppeoples ORDER BY AffinityBloc, PeopleCluster, PeopNameAcrossCountries, Ctry";
$rs = $db->Execute($sql) or die("Query Failure: Turn Debug On to Find Out Why");
$last_affinity = "";
$last_pplclust = "";
$last_pplgroup = "";
while (!$rs->EOF) {
$r0 = $rs->fields[0];
$r1 = $rs->fields[1];
$r2 = $rs->fields[2];
$r3 = $rs->fields[3];
$r4 = $rs->fields[4];
$r5 = $rs->fields[5];
$r6 = $rs->fields[6];
$r7 = $rs->fields[7];
if ($last_affinity != $r1) {
// Start a New Affinity Element
echo "<li>";
echo "<a href=\"affinitybloc.php?rop1=$r0\" title=\"Click for detailed listing of this Affinity Bloc\">$r1</a>\n";
if ($last_pplclust != $r3) {
// Start a New People Cluster
echo "<ul>";
echo "<li>";
echo "<a href=\"peopcluster.php?rop2=$r2\" title=\"Click for detailed listing of this People Cluster\">$r3</a>";
if ($last_pplgroup != $r5) {
// Start a New People Group
echo "<ul>";
echo "<li>";
echo "<a href=\"peoples.php?rop3=$r4\" title=\"Click for detailed listing of this People Group\">$r5</a>";
// Start a New People/Crty
echo "<ul>";
echo "<li>";
echo "<a href=\"peopctry.php?rop3=$r4&rog3=$r6\" title=\"Click for People profile in this Country\">$r7</a>";
echo "<li>";
} else {
echo "<li>";
echo "<a href=\"peopctry.php?rop3=$r4&rog3=$r6\" title=\"Click for People profile in this Country\">$r7</a>";
echo "<li>";
}
}
}
$rs->MoveNext();
}