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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘