I’m a first-time poster so please be gentle!
I’m having a bit of a problem. I’m trying to create a click-to-collapse side-navigation bar that is populated by a MySQL database that pulls the name and sorts via number. I’ve gotten the first teir working, but when running the second teir it will only populate the first item in the first teir. It skips the rest.
This is what I want it to do:
[b]Division 1
–Department 1
–Department 2
[b]Division 2
–Department 1
–Department 2
[b]Division 3
–Department 1
–Department 2
This is what it is doing:
[b]Division 1
–Department 1
–Department 2
[b]Division 2
Division 3
Here is my code:
[code]
<html>
<head>
<style>
<!– div#myToggledDiv {display: none;} –>
</style>
<script type=”text/javascript”>
function swapMyToggledDiv(div)
{
if (document.getElementById(div).style.display == “block”)
{ document.getElementById(div).style.display = “none”; }
else
{ document.getElementById(div).style.display = “block”;}
}
</script>
<body>
<?php
include(“connect.php”);
//Setting up Queries
$get_division = “SELECT div_name, div_num FROM division ORDER BY div_num;”;
$get_dept = “SELECT dept_name, dept_num FROM dept ORDER BY dept_num;”;
$get_productline = “SELECT prodline_name, prodline_num FROM product_line ORDER BY prodline_num;”;
//Running Queries
$division_results = mysql_query($get_division) or die(mysql_error());
$dept_results = mysql_query($get_dept) or die(mysql_error());
$productline_results = mysql_query($get_productline) or die(mysql_error());
if (mysql_num_rows($division_results) < 1 && mysql_num_rows($dept_results) < 1 && mysql_num_rows($productline_results) < 1)
{
$display_block = “<P><em>Sorry, no categories to browse.</em></p>”;
}
else
{
while ($div = mysql_fetch_array($division_results))
{
$div_num = $div[div_num];
$div_name_u = strtoupper(stripslashes($div[div_name]));
$div_name = $div[div_name];
$display_block .= “<div onClick=”swapMyToggledDiv(‘$div_name’)”> nt <img src=’closed.gif’> nt <b> $div_name_u </b> n </div> n <div id=”$div_name”>n”;
while ($dept = mysql_fetch_array($dept_results))
{
$dept_num = $dept[dept_num];
$dept_name_u = strtoupper(stripslashes($dept[dept_name]));
$dept_name = $dept[dept_name];
if($dept_test = substr($dept_num,0,-1) == $div_num)
{
$display_block .= “<div onClick=”swapMyToggledDiv(‘$dept_name’)”> nt <img src=’closed.gif’> nt <b> $dept_name_u </b> <br> n </div> n<div id=”$dept_name”>”;
$display_block .=”</div>nn”;
}
}
unset($dept);
$display_block .=”</div>nn”;
}
}
echo ($display_block);
?>
</body>
</html>
Any help would be greatly appreciated!
Thanks!