duandai6373 2013-05-08 13:51
浏览 32

菜单从数据库填充

I am trying to create a side navigation populated from the database. I want the categories to show up on the left hand side and when you click on one the others slide down to make room for the sub categories. However I am having trouble getting them to work properly.

I got the main categories up and running and got it to slide down and display a subcategory hard coded saying "hello world" but now i am trying to populate the sub categories with those from the database I am having trouble getting it all to work.

Here is my code:

this is my database connection

<?php 
    $base = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
        $mysql_connection = db_connect_enhanced('*********','dbaccess','*******','website');    //Connect to database
        $categories = "SELECT * FROM *********** WHERE active = 1";
        $result = db_query_into_array_enhanced($mysql_connection, $categories);
        $count = count($result);
?>

Here is the code to display my navigation

    <div id="left-prod-nav">
        <ul>
            <li class="top">Product Categories</li>
            <?for($i = 0; $i < $count; $i++) 
            {?> 
            <div class="flip"><li><img src="images/arrowright_off.gif" style="padding:0px; margin:0px;float:right;"><a href="#"><?=$result[$i]['categoryName']?></a></li> </div>
                    <? $subCategories = "SELECT * FROM ************* WHERE active = 1";
                    $subCatResult = db_query_into_array_enhanced($mysql_connection, $subCategories);
                    $subCount = count($subCatResult);
                    for($i = 0; $i < $subCount; $i++) 
                    {?>
                        <div class="panel"><?=$subCatResult[$i]['categoryName']?></div>
                    <?}?>

            <?}?>
        </ul>
        <div class="clear">&nbsp;</div>
    </div>

Here is the javascript that gets the navigation to slide down and up on click

<script> 
    $(document).ready(function(){
        $(".flip").click(function(){
            $(this).next(".panel").slideToggle("slow");
        });
    });
</script>

as i said, getting the top tier nav to work was fine. it displayed the categories from the database and slid down when clicked. but now im trying to display the sub categories when it slides down I cant.

Any help is greatly appreciated

  • 写回答

2条回答 默认 最新

  • dph87312 2013-05-08 14:13
    关注

    This happens due to several things in your code

    1.In you query , you are setting

    SELECT * FROM ************* WHERE active = 1
    

    How it will differentiate the parent category ? Check For: Is it returning value ?

    2.May be CSS problem too, can you check for .panel { ... } in your css

    3.You closed your Flip Div at the catagory name itself, complete it after panel is over

      <?}?>
          <?}?>
              </div> //Flip div
                  </ul>
    

    4.Pl try this plain html and check if it works, then you can confirm , which error...is it db or jquery :) Try this:

    <div id="left-prod-nav">
            <ul>
                <li class="top">Product Categories</li>
                <div class="flip"><li><img src="images/arrowright_off.gif" style="padding:0px; margin:0px;float:right;"><a href="#">categoryName</a></li> </div>
                 <div class="panel">c1</div>
                 <div class="panel">c2</div>
                 <div class="panel">c3</div>
                  <div class="panel">c4</div>         
            </ul>
    <div class="clear"></div>
    </div>
    

    Hope it helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算