Hello all..
I've done some PHP in my day, but I'm no guru, and I've been stuck trying to get one function to work properly.
What I want in a nutshell is an nested list with "Clusters" then SubClusters" listed under the appropriate cluster.
I have a database full of rows with cluster / subcluster declaration.
Here's the thing.
A row may have a cluster only.. subcluster is totally optional.
So, I need to be able to pull all the cluster and subcluster names, and nest the subclusters properly underneath their parent cluster.
It's probably something stupid I'm just overlooking....
Here's what I have working, except for the fact that its showing duplicate clusters ( I know why I have dups, but this gives me all the info I want to display)
echo'<ul>';
$result = mysql_query("SELECT cluster, subcluster FROM TABLE GROUP BY cluster, subcluster");
while ($row = mysql_fetch_array($result))
{
if($row["subcluster"] != null)
{
echo '<li><a href="index.php?sort='.$row["cluster"].'">'.$row["cluster"].'</a></li>';
echo '<ul>';
echo '<li><a href="index.php?sort='.$row["subcluster"].'">- '.$row["subcluster"].'</a></li>';
echo '</ul>';
}
else
{
echo '<li><a href="index.php?sort='.$row["cluster"].'">'.$row["cluster"].'</a></li>';
}
}
echo '</ul>';