Jump to content

[SOLVED] help on vertical menu


pixeltrace

Recommended Posts

Hi,

 

anyone here has done a vertical menu using php with mysql database?

something like this

 

menu1

  > submenu1

  > submenu2

  > submenu3

menu2

  >submenu4

  >submen5

 

then when you click the menu it shows/ hide the submenu.

 

 

hope you could help me with this.

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/69923-solved-help-on-vertical-menu/
Share on other sites

if SEO is important, avoid Javascript navigation. here is where i get CSS menus: http://www.dynamicdrive.com/dynamicindex1/indexb.html

 

(includes browser compatibility info)

 

if SEO is important, but so is the greatest browser/machine compatibility, you're best off with static (non-closing) navigation, i.e., a link list.

 

 

Hi,

 

i found a easy way,

i just used a javascript that will show or hide the submenus.

but i have a problem, i need to have the value of my id to increment +1 for every count of my main menu

and i dont know how to do it.

i placed 1++ on the parameter that i wanted to increment +1 but its not working and i am getting an error

Parse error: syntax error, unexpected T_INC in /home/brennan/public_html/ideas-people/engsoon/products/test.php on line 26

 

below is my current code

<? include '../admean/db_connect.php'; ?>

<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

<table width="400" border="0" cellspacing="0" cellpadding="0">
<?
		$uSql = "SELECT category_name, cid FROM engsoon_categories WHERE parent ='0'";
		$uResult = mysql_query($uSql, $connection);
		if(!$uResult){
		echo 'no data found';
		}else{
		while($uRow = mysql_fetch_array($uResult)){
		$pid = $uRow["cid"];
			?>
  <tr>
    <td><a href="javascript;" onclick="toggle_visibility('<? 1++ ?>');"><?= $uRow['category_name']; ?></a>

				   <? $sql2  = "SELECT category_name, cid FROM engsoon_categories WHERE parent='$pid'";
						$result = mysql_query($sql2, $connection);
						if(!$result){
						echo 'no data found';
						}else{
						while($row = mysql_fetch_array($result)){
						$cname = $row['category_name'];
						?>
						<? echo "<table id=" . 1++ ."><tr><td>--"."$cname"."</td></tr></table>";
						}
						} ?>
</td>
  </tr>
  <?
   }
  }
  ?>
</table>
</body>
</html>

 

 

hope you could help me fix this.

 

thanks!

hi,

 

i tried it but its still not working.

i check the source code of the html output and here is how it look like

<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

<table width="400" border="0" cellspacing="0" cellpadding="0">
   <tr>
    <td>
<a href="#" onclick="toggle_visibility('');">testparent1</a>

				   							<table id=2><tr><td>--testsubcategory2</td></tr></table>							<table id=3><tr><td>--testsub</td></tr></table>	</td>
  </tr>
    <tr>
    <td>
<a href="#" onclick="toggle_visibility('');">testparent2</a>

				   							<table id=5><tr><td>--testsubcategory1</td></tr></table>							<table id=6><tr><td>--testsubcategory2</td></tr></table>	</td>
  </tr>
  </table>
</body>
</html>

 

what i wanted to achieve is that

the toggle visibility () value of testparent1 will be equal to the

table id= of

testsubcategory2

testsub

 

so forth and so on.

 

how can i make it work that way?

 

hope you could help me with this.

 

thanks!

Hi,

 

problem solve already.

 

thanks for all the help.

 

just for reference, this is my working code

<? include '../admean/db_connect.php'; ?>

<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

<table width="400" border="0" cellspacing="0" cellpadding="0">
<?
		$uSql = "SELECT category_name, cid FROM engsoon_categories WHERE parent ='0'";
		$uResult = mysql_query($uSql, $connection);
		if(!$uResult){
		echo 'no data found';
		}else{
		$i = 1;
		while($uRow = mysql_fetch_array($uResult)){
		$pid = $uRow["cid"];
		$category_name = $uRow['category_name'];
		//$keys = array_keys ($category_name); 
						?>
  <tr>
    <td>
<a href="#" onclick="toggle_visibility('<? echo "$i"; ?>');"><? echo "$category_name"; ?></a>

				   <? $sql2  = "SELECT category_name, cid FROM engsoon_categories WHERE parent='$pid'";
						$result = mysql_query($sql2, $connection);
						if(!$result){
						echo 'no data found';
						}else{
						echo "<table id=" . $i ." style='display:none'>";
						while($row = mysql_fetch_array($result)){
						$cname = $row['category_name'];
						?>
						<? echo "<tr><td>--"."$cname"."</td></tr>";
						}
						echo "</table>";
						} ?>
</td>
  </tr>
  <?
  $i++;
   }
  }
  ?>
</table>
</body>
</html>

 

thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.