动态twitter bootstrap手风琴

时间:2013-07-31 00:12:14

标签: php twitter-bootstrap

您好我想让我的twitter bootstrap手风琴将某些物品放在同一个手风琴组中。我的意思是代替它显示为:

  • commentA
    • subcommentA
  • commentB
    • subcommentB
  • commentA
    • subcommentC

我希望它显示为

  • commentA
    • subCommentA
    • subcommentC
  • commentB
    • subcommentB

我一直试图用php / mysql动态地做这个,但是我得到的第一个例子而不是第二个例子。我在下面附上了我的代码。

function printSubComments(){
       $currAd = new userAds();
       $currAdImages = new images();
       $ad_id = $currAdId = $_GET['id'];
       $user_id = $currAd ->getUserIdByAdId($ad_id);
       echo'<center><h4>Further comments about this user:</h4></center>';
       $queryComment = mysql_query("SELECT visitor_comment FROM user_connection WHERE user_id='$user_id' AND visitor_vote='1'") or die(mysql_error());
       $data = mysql_fetch_assoc($queryComment);
       $comment = $data['visitor_comment'];
       $rows = mysql_num_rows($queryComment);

       if($rows != 0){
         echo
         '
           <div class="accordion" id="accordion2">
         ';
              $i = 0; $j = 0;
              while($i < $rows){
              $querySubComment = mysql_query("SELECT visitor_sub_comment FROM user_connection WHERE user_id='$user_id' AND visitor_comment='$comment'") or die(mysql_error());
                  $data = mysql_fetch_assoc($querySubComment);
              $subComment = $data['visitor_sub_comment'];
                  echo
                  '
                     <div class="accordion-group">
            <div class="accordion-heading">
               <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse'.$i.'">
                  '.$comment.'
               </a>
            </div>
            <div id="collapse'.$i.'" class="accordion-body collapse">
                <div class="accordion-inner">
                   <ul id="subComments">
                   <li>'.$subComment.'</li>
                   </ul>
                </div>
            </div>
                 </div>
                  ';
                  $i++;
              }

         echo
         '     
           </div>
         ';
       }else{
         echo'<center><h5>No comment about this user at this point.</h5></center>';
       }
    }

我在想,也许我应该在第二次循环时再次查询数据库中与任何给定注释相关联的子注释但是我慢慢地将服务器关闭。然后我想如果我做了strcmp比较与每个子注释相关的每个注释并将其添加到某种类型的数组中。这似乎过于复杂和不合时宜。任何帮助将不胜感激。

0 个答案:

没有答案