dtny30176 2015-03-04 17:40
浏览 36

为什么我的php数组只返回最近/最后发布的活动

I create a jquery which sent data to a php file and after query(If any data found at sql) php return data to jquery by json_encode for append it.

Jquery sent two type data to php file:

1st: page id

2nd: post ids (a jquery array sent them to php file)

If I used print_r($_REQUEST['CID']); exit; on php file for test what he get from jquery, Its return and display all post ids well.

But if I make any reply on particular post, Its only return recent post reply.

That means, if I have 3 post like: post-1st, post-2nd, post-3rd ; my php return only post-3rd activities.

I want my script update any post reply when it submitted at sql.

my wall.php

    // id is dynamic
<div class="case" data-post-id="111"></div> 
<div class="case" data-post-id="222"></div>
<div class="case" data-post-id="333"></div>

//Check for any update after 15 second interval by post id.
<script type="text/javascript" charset="utf-8">

var CID = [];
$('div[data-post-id]').each(function(i){
    CID[i] = $(this).data('post-id');
});

function addrep(type, msg){
CID.forEach(function(id){
    $("#newreply"+id).append("<div class='"+ type +""+ msg.id +"'><ul>"+ msg.detail +"</ul></div>");
});
}
var tutid = '<?php echo $tutid; ?>';
function waitForRep(){
    $.ajax({
        type: "GET",
        url: "/server.php",
        cache: false,
        data: {
        tutid : tutid,
        CID : CID
    },
        timeout:15000, 
        success: function(data){ 
            addrep("postreply", data);
            setTimeout(
                waitForRep, 
                15000 
            );
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            setTimeout(
                waitForRep, 
                15000); 
        }
    });
}

$(document).ready(function(){
    waitForRep();
});
</script>

server.php (may be problem in my array or something else)

while (true) {
if($_REQUEST['tutid'] && $_REQUEST['CID']){
foreach($_REQUEST['CID'] as $key => $value){

date_default_timezone_set('Asia/Dhaka');
$datetime = date('Y-m-d H:i:s', strtotime('-15 second'));
$res = mysqli_query($dbh,"SELECT * FROM comments_reply WHERE post_id =".$value." AND qazi_id=".$_REQUEST['tutid']."  AND date >= '$datetime' ORDER BY id DESC LIMIT 1") or die(mysqli_error($dbh));

} // array close

$rows =  mysqli_fetch_assoc($res);  

        $row[] = array_map('utf8_encode', $rows);

        $data = array();

$data['id'] = $rows['id']; 
$data['qazi_id'] = $rows['qazi_id'];
//ect all

// do something and echo $data['detail'] = $detail;

    if (!empty($data)) {
        echo json_encode($data);
        flush();
        exit(0);
    }

}  // request close
sleep(5);
}  // while close
  • 写回答

2条回答 默认 最新

  • dongpigui8898 2015-03-04 18:00
    关注

    Try to declare CID array like this:

    var CID = new Array();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题