Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Navigation from SQL

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
r937 has seriously helped me creating an excellent query that pulls my site's navigation into a table in this manner:
Code:
 _________________________________________________
| root    |         |         |         |         |
---------------------------------------------------
| root    | nav1a   |         |         |         |
---------------------------------------------------
| root    | nav1a   | nav2    |         |         |
---------------------------------------------------
| root    | nav1a   | nav2    | nav3a   |         |
---------------------------------------------------
| root    | nav1a   | nav2    | nav3b   | nav4    |
---------------------------------------------------
| root    | nav1b   |         |         |         |
---------------------------------------------------
| root    | nav1c   |         |         |         |
---------------------------------------------------
| root    | nav1c   | nav2a   |         |         |
---------------------------------------------------
| root    | nav1c   | nav2a   | nav3a   |         |
---------------------------------------------------
| root    | nav1c   | nav2a   | nav3b   |         |
---------------------------------------------------
| root    | nav1c   | nav2a   | nav3c   |         |
---------------------------------------------------
| root    | nav1c   | nav2b   |         |         |
---------------------------------------------------
| root    | nav1c   | nav2b   | nav3    |         |
---------------------------------------------------

This can go up to 8 dimensions out. Now I'm trying to display it on the page. I have it sort of working, but I'd like to make it like a tree that expands and collapses. (I would also like it to be persistent, but I'm not even sure where to begin on that...)

This is the code that displays my navigation completely:
Code:
<?php $t = 0; $ready = false;
while ($row_navigation = mysql_fetch_assoc($navigation)) {
	if($root != $row_navigation['root_name']){
		if($t != 0){ echo "</div><br>"; } ?>
		<a onClick="toggleNav('nav<?php echo $t; ?>')" style="cursor:pointer;">&gt;
		<?php echo $row_navigation['root_name']; ?></a><br />
		<div id="nav<?php echo $t; $t++; ?>" style="display:none;">
		<?php $ready = true;
	}
	
	if($ready == true){ for($d=1;$d<=8;$d++){
		if(${"down".$d} != $row_navigation['down'.$d.'_name'] && $row_navigation['down'.$d.'_name'] != ""){ 
			for($spaces=0;$spaces<=($d*3);$spaces++){ echo "&nbsp;"; }
				echo $row_navigation['down'.$d.'_name'];
				${"down".$d} = $row_navigation['down'.$d.'_name'];
				echo "<br />";
			}
		}
	}
	
	$root = $row_navigation['root_name'];
	} ?>
</div>

Now, somewhere in the second section (after $ready == true), I need open and close [tt]<div>[/tt] tags when a new sub-directory is opened and closed. Just the concept of this has been driving me crazy. It's difficult for my brain to perform this loop in my head.

I would like to eventually get a + and - to switch these items.

Thanks.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top