i found a way to display the information they way that i want!!! but i geting a extra ul in the output. i try many thing to remove this ul but i can't seem to find the right way to get this extra ul removed. Any Idea on right place to add code to remove this extra ul
This site:
The Site
The html Output:
<ul>
<li>Agricultural and Environmental Sciences
<ul>
<li>Agricultural Leadership, Education and Communication</li>
<li>Animal and Dairy Science</li>
<li>Biological and Agricultural Engineering</li>
<li>Crop and Soil Sciences</li>
<li>Entomology</li>
<li>Food Science and Technology</li>
<li>Horticulture</li>
<li>Plant Pathology</li>
<li>Poultry Science</li>
</ul>
</li>
<ul> <!-- The extra ul -->
<li>Business
<ul>
</li>
</ul>
The Code:
<?php
$query = mysqli_query($link,'SELECT colleges.college_id,colleges.college_name, departments.department_id,departments.department_name FROM colleges INNER JOIN departments ON colleges.college_id = departments.college_id' );
echo "";
while ($row = mysqli_fetch_assoc($query))
{
//Get the current rows id
$current_id = $row['college_id'];
//Did we already see this?
if ($current_id == $old_id)
{
//OK, we are still in the same group, just display child
echo "<li>" . $row['department_name'] . "</li>";
}
else
{
//New group, display parent record
if($current_id > 1){ echo "</ul></li>";}
if($current_id = 1){ echo "<ul>";}
echo "<li>" . $row['college_name'];
echo "<ul>";
}
//Remember id
$old_id = $current_id;
}
echo "</li></ul>";
?>