Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Collapsing menu

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
11
Im working on the menu at my site http://tutorialhit.com/index.php

i want to be able to click the main category (in this case, only one is there, and called PHP coding) and it would display all of the sub-categories in only that category (there will be more main categories added). Then if you click the PHP coding category again, the sub-categories go away again.

The categories are all in the mysql database

This is the code for the subcategories

PHP:
		if(count($children)>"0"&&$foetus!="") {
			foreach($children as $child) {
				$k++;
				$title = mysql_result(mysql_query("SELECT * FROM tdb_categories WHERE id='$child' LIMIT 1"), "0", "title");
				$stati = mysql_result(mysql_query("SELECT * FROM tdb_categories WHERE id='$child' LIMIT 1"), "0", "status");
				if($stati=="open") {
					$colspan = "1";
					$link = '<a href="list.php?cat='.$child.'">'.$title.'</a></td><td class="info">'.mysql_numrows(mysql_query("SELECT * FROM tdb_tutorials WHERE cat='$child' AND status='accepted'")).' ×';
				} else {
					$link = ''.$title.'';
					$colspan = "2";
				}
				echo '<tr class="menu'.$k.'subcat"><td class="link" colspan="'.$colspan.'">'.$link.'</td></tr>';
				if($k=="2") {
					$k = "0";
				}
			}
		}

If you dont know what i mean, i found an example: http://www.chipchapin.com/WebTools/MenuTools/xpandmenu-2004-12-16/demo_win.php



If i know the code on how to make you click on a link and gives text to a certain variable but the page doesnt reload or something, then i can probably do it.

Ie
PHP:
$activelink="";

//code to click the text below and add $title (category title) to the variable
Category name

// Then display sub-categories whos parent is $title (category title that was clicked)
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
•••
I dont think that would work for me, because there would be no way to tell what category was clicked and what subcategories to display.
 
0
•••
I'm trying to figure out how to implement it into the PHP, but here's the Javascript:
Code:
<script type="text/javascript">
function showList(element) {
if (document.getElementById(element).style.visibility == "collapse") {
document.getElementById(element).style.visibility = "visible";
} else {
document.getElementById(element).style.visibility = "collapse";
}
}
</script>

This worked for me:
PHP:
<?
$sql = mysql_query("SELECT * FROM db WHERE status='0'");
while ($row = mysql_fetch_object($sql, MYSQL_BOTH)) {
    echo '<strong><a href="javascript:showList(\''.$row->TITLE.'\');">'.$row->TITLE.'</a></strong><br />
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="visibility:collapse;" id="'.$row->TITLE.'">';
     $sql2 = mysql_query("SELECT * FROM db WHERE PARENT = '".$row->TITLE."' AND STATUS = '1'");
	 while ($row2 = mysql_fetch_object($sql2, MYSQL_BOTH)) {
	 echo '<tr><td><a href="'.$row2->LINK.'" target="_blank">'.$row2->TITLE.'</a></td></tr>';
	 }
	 echo '</table>';
}
?>
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back