消息页面中的显示较早消息按钮出现问题

时间:2019-07-18 16:16:54

标签: php jquery mysql

我正在两个人之间建立一个消息页面,并且我有一个带有人名的菜单,当我单击每个名字显示时都是对话。
现在,我尝试添加一个按钮以显示较旧的消息,并且如果我只与一个人交谈,我的代码也可以正常工作。
如果对话不止一个人,那么很多聊天都不会显示,我也不知道到底是什么问题。

这是msg.php文件:

<style>
    .hmttm{position: relative;left: 20px;top: 60px;color: black}
</style>
<?php require_once('mmnu.php');?>
<?php 
if (isset($_GET['msg']))
{
    $u5 = $_GET['msg'];
    ?>
    <div style="position: relative;left: 200px;top: 100px">
        <button id="bt1" >older messages...</button>
        <div  id="co2" style=""></div>
    </div>
<?php 
} 
?>

<script>
    $(document).ready(function() {
        var u5   = <?php echo $u5; ?>;
        var uid  = <?php echo $uid; ?>;
        var com2 = 2;
        var off2 = 2;
        var p_n2 = 0;

        $("#bt1").click(function() {
            $.ajax({
                method: "POST",
                url: "z_msg.php",
                data: { com2: com2, p_n2 : p_n2, u5 : u5, uid: uid}
            })
            .done(function(msg2) {
                if (msg2 == ' ') {
                    $("#bt1").hide();
                } else {
                    $("#co2").prepend(msg2);
                }
            });

            p_n2 = p_n2 + 1;
            com2 = com2 + 2;
        });

        $("#bt1").trigger("click");
    });
</script>

z_msg.php:

<?php
$com2 = $_POST['com2'];
$p_n2 = $_POST['p_n2'];
$u5   = $_POST['u5'];
$uid  = $_POST['uid'];

$rzp = mysqli_query($conn, "SELECT * FROM t_msg WHERE id > 
    ((SELECT MAX(id) FROM t_msg) - '$com2') 
    AND 
    (
        (for_u = '$uid' AND u_sender = '$u5') 
        OR 
        (for_u = '$u5' AND u_sender = '$uid')
    ) 
    LIMIT 0, 2");

$rzp2 = mysqli_query($conn, "SELECT id FROM t_msg WHERE 
    (for_u = '$uid' AND u_sender = '$u5')
    OR 
    (for_u = '$u5' AND u_sender = '$uid')");

$ncm = 0;
if ($rzp2) {
    $ncm = mysqli_num_rows($rzp2);
}

$l_r = $p_n2 * 2;

if ($l_r >= $ncm) {
    echo ' ';
    exit();
} else {

    while ($rpz = mysqli_fetch_assoc($rzp)) { 
    ?>
        <div style="position: relative;left: 200px;top: 200px">
        <?php 
        $pdt = $rpz['u_sender'];
        $pmg = $rpz['msg'];
        $id  = $rpz['id'];

        if ($pdt==$uid) { 
        ?>

            <div class="mym"><?php echo $pmg ?></div>

        <?php 
        } elseif ($pdt == $u5) {
        ?>

            <div class="on"><?php echo $pmg ?></div>

        <?php 
        }
        ?>
<?php   
    }
}
?>
</div>

然后mnu.php显示人员姓名,并发送GET的人证。

谢谢

0 个答案:

没有答案