Jump to content

[SOLVED] help on vertical menu


pixeltrace

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.