|
Posted by Chris on 05/15/06 23:20
I've been working on a basic Parent/Child Menu where if you click on the
Parent link the Child set of links appears, then when clicked again, it
disappears. All the parent/child elements are propagated from a MySQL
database, and there is only 1 set of children to each parent. I have seen
dozens of Tree menus, but the links are all hard-coded, and have found a few
other references for it, but it seems that you can't really do it solely in
PHP, but with Javascript/CSS and an OnClick event.
Much of what I've seen is old (pre-2002) or they refer to some commercial
menu-building program (why spend $$ on a program that generates 20 different
kind of menus when you really only need one kind? Sort of like buying the
entire CD when you only like one song on the whole thing.). Could this be
done with an if statement - perhaps as a PHP function to be called with
isset?
There are ways to pass JS variables back and forth with PHP, but I would
like it to be simpler. I am working with 2 different servers - one -the
test server-is running PHP 5.1.2 (Win2003), and the other -the current
production server- is running PHP 4.3.2 (Linux).
Also, I would like some advice on the db architecture. Should the parent &
child categories be in the same db table or as separate tables (one for
Parents/one for Children with a ref back to the parent - this is how I'm
currently doing it)?
Thanks,
Chris
This is the code basics I have now combining with JS, and it doesn't work:
<script language="Javascript">
function displayMenu(currentMenu) {
var thisMenu = document.getElementByID(currentMenu).style
//If menu is expanded, contract it
if (thisMenu.display == "block") {
thisMenu.display = "none"
}
else {
//If menu is contracted, expanded it
thisMenu.display = "block"
}
return false
}
</script>
<style type="text/css">
..dropmenu {
display:none;
margin-left:10px;
}
</style>
<?php
//code to access parent category table in db and select query
?>
<?php do { ?>
<table width="145" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="javascript" onClick="return
displayMenu('child')"><?php echo $row_categories['category']; ?></a>
</td>
</tr>
</table>
<?php
//code to access child category table in db and select query
?>
<?php do{ ?>
<span class="dropmenu" id="child">
<?php echo $row_subcat['subcategory']; ?>
<br />
</span>
<?php } while ($row_subcat = mysql_fetch_assoc($subcat)); ?>
<?php } while ($row_categories = mysql_fetch_assoc($categories)); ?></td>
Navigation:
[Reply to this message]
|