php mysqli中的两个用户对话URL

时间:2019-12-07 19:15:43

标签: php session mysqli

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

对不起,我的英语不好。

我的数据库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";
    }

    ?>

2 个答案:

答案 0 :(得分:1)

希望我这次明白了

这是我的代码:

select p.*
from products p
where not exists (select 1
                  from orders o
                  where o.product_id = p.product_id and
                        o.orderdate >= dateadd(day, -90, getdate())
                 );

答案 1 :(得分:1)

也更改您的URL。

<a href="cons.php?to_id=<?php if(isset($_GET['to_id'])) {$to_id=$_GET['to_id']; echo $to_id;}?>">Replay</a>

使用此代码。

<?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";
    }

    ?>