douyou1960 2017-11-17 08:25
浏览 49
已采纳

使用php mysql循环jquery函数load()不起作用它只循环第一行

I need to show the posts count depend on topic id using auto load jquery load() after looping the result using php but unfortunately it shows the first row and uses that first row to show another count and change again Any Help please!


index.php

    <?php
    foreach($t_all_rows as $row){
            ?>
         <tr>
             <td class="text-center hidden-xs hidden-sm">
                 <a class="font-w600" href="javascript:void(0)">
                    <script type="text/javascript">
                                    var auto_refresh = setInterval(
                                    function ()
                                    {
            $('#load_posts').load('get_posts.php?t_id=<?php echo $row['t_id']; ?>').fadeIn("slow");
                                    }, 1000); // refresh every 5000 milliseconds
                                    </script>

                                   <span id="load_posts"></span>
                </a>
          </td>
       </tr>
       <?php } ?>

get_posts.php

    include('connection.php');
    $db=new DB();
    $conn=$db->db_connect();
    $my_t_id=$_GET['t_id'];
    $post_query = mysqli_query($conn,'SELECT * FROM post WHERE t_id = "'.$my_t_id.'"');
    $record_count=mysqli_num_rows($post_query);
    //Display count.........
    echo $record_count;
  • 写回答

2条回答 默认 最新

  • duan0531 2017-11-17 10:32
    关注

    that is normal, because get only first div by ID, change the span id or add a new class with loop number

    Adding $k

        foreach($t_all_rows as $k =>  $row){
    

    Adding new class

    <span id="load_posts" class="load_post<?=$k?>"></span>
    

    change jquery code:

    $('.load_post<?=$k?>').load
    

    But importan, I am suggest to you, to upgrate the mysql query using JOIN and not use jquery

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面