NameSilo

Collapsing menu

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
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
Close
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
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back