dongsibao8977 2015-08-03 10:06
浏览 25
已采纳

Modal为所有记录弹出相同的信息

I am looping a DIV with foreach loop. my PHP looks like this:

   <?php foreach ($record as $row) { //looping the records ?>
   <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
     Launch demo modal
    </button>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
    </div>
    </div>
   <?php } ?>

And the modal always show the first entry of the loop.. however in the html source code i can see all the records. How do i trigger each result individually?

  • 写回答

1条回答 默认 最新

  • dongtang7347 2015-08-03 10:10
    关注

    data-target="#myModal" will use the id attribute. And multiple elements can not have the same id. Use different id for different modal.

    <?php
         $i = 0; 
         foreach ($record as $row) { //looping the records 
    ?>
    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
     Launch demo modal
    </button>
    
    <div class="modal fade" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
    </div>
    </div>
    <?php 
        $i++;
     } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料