pixeltrace Posted September 19, 2007 Share Posted September 19, 2007 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! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 19, 2007 Share Posted September 19, 2007 i suggest that you search for 'css menu' neither php nor mysql are required to make an expanding menu. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 19, 2007 Share Posted September 19, 2007 Also, to make them show/hide, you'll have to use javascript. (Or a css hack which doesn't work on all browsers) Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 19, 2007 Share Posted September 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
pixeltrace Posted September 19, 2007 Author Share Posted September 19, 2007 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! Quote Link to comment Share on other sites More sharing options...
sasa Posted September 19, 2007 Share Posted September 19, 2007 change 1++ to ++$sasa Quote Link to comment Share on other sites More sharing options...
pixeltrace Posted September 19, 2007 Author Share Posted September 19, 2007 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! Quote Link to comment Share on other sites More sharing options...
pixeltrace Posted September 19, 2007 Author Share Posted September 19, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.