[php mysqli中的两个用户对话URL

问题描述 投票:0回答:2

output image output image 2我正在PHP mysqli中创建两个用户对话视图脚本。我的脚本(如果其他用户的最后一条消息是URL打开),但是当我作为最后一条消息发送时,它没有打开,因为它显示了我的ID,因此我想获取另一个没有我的ID的用户ID到URL,

对不起,我的英语不好。

我的数据库pm表

id  from_id    to_id     msg               sent_date
1   2          3         hi how are you?   2019-12-05 04:14:20
2   3          2         fine              2019-12-05 05:15:58
3   2          3         hi                2019-12-05 03:20:34
4   5          2         hi                2019-12-05 08:30:40

网址

<a href="cons.php?to_id=<?php echo $row['from_id'];?">Replay</a>

这是我的源代码

  <?php
    require_once"config.php";
    if (isset($_SESSION['userid'])) {
    $to_id = $_SESSION['userid'];  
    }

    if ($stmt = $con->prepare("SELECT * FROM pm WHERE from_id = ? OR to_id = ?  ORDER BY sent_time DESC")) {
        $stmt->bind_param('ii', $to_id, $to_id);
        $stmt->execute();
    }

    $tempArray = array();

    $result = $stmt->get_result();
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {

          if (!in_array($row['to_id'].$row['from_id'], $tempArray)) {
            echo "<br>";
            echo $row['from_id']." - " . $row['to_id']." ". $row['msg']. " - " .$row['sent_time'];


    ?>

 <a href="cons.php?to_id=<?php echo $row['from_id'];?">Replay</a>

    <?php }?>
    <?php


          array_push($tempArray, $row['from_id'].$row['to_id']);
          array_push($tempArray, $row['to_id'].$row['from_id']);

        }
    } else {
        echo "NO MESSAGES";
    }

    ?>
php session mysqli
2个回答
0
投票

我不太了解您的问题。但是我有一个线索,你想要什么,或者是一个猜测。如果要将URL的get请求用作$ to_id,则应使用$ _GET而不是$ _SESSION。


0
投票

使用此代码。

<?php
    require_once"config.php";
    if (isset($_SESSION['userid'])) {
    $from_id = $_SESSION['userid'];  
    }
    if (isset($_GET['to_id'])) {
    $to_id= $_GET['to_id'];  
    }

    if ($stmt = $con->prepare("SELECT * FROM pm WHERE from_id = ? OR to_id = ?  ORDER BY sent_time DESC")) {
        $stmt->bind_param('ii', $from_id, $to_id);
        $stmt->execute();
    }

    $tempArray = array();

    $result = $stmt->get_result();
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {

          if (!in_array($row['to_id'].$row['from_id'], $tempArray)) {
            echo "<br>";
            echo $row['from_id']." - " . $row['to_id']." ". $row['msg']. " - " .$row['sent_time'];


    ?>

 <a href="cons.php?to_id=<?php echo $row['from_id'];?">Replay</a>

    <?php }?>
    <?php


          array_push($tempArray, $row['from_id'].$row['to_id']);
          array_push($tempArray, $row['to_id'].$row['from_id']);

        }
    } else {
        echo "NO MESSAGES";
    }

    ?>
© www.soinside.com 2019 - 2024. All rights reserved.