php mysqli中的两个用户对话URL

php mysqli中的两个用户对话URL,php,session,mysqli,Php,Session,Mysqli,我正在用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

我正在用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
网址


这是我的源代码

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

    ?>

希望这次我能理解

这是我的密码:

  if (isset($_SESSION['userid'])) {
    $session_id = $_SESSION['userid'];
  }

  if ($stmt = $con->prepare("SELECT * FROM pm WHERE from_id = ? OR to_id = ? ORDER BY sent_date DESC")) {
    $stmt->bind_param('ii', $session_id, $session_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'];


        $guaranteed_from_id = str_replace($session_id, null, $row['to_id'].$row['from_id']);

        ?>

        <a href="cons.php?to_id=<?php echo $guaranteed_from_id ?>">Replay</a>

        <?php

 }


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

      }
  } else {
      echo "NO MESSAGES";
  }
if(isset($\u会话['userid'])){
$session\u id=$\u session['userid'];
}
如果($stmt=$con->prepare($SELECT*FROM pm WHERE FROM\u id=?或to\u id=?按发送日期描述订购”)){
$stmt->bind_参数('ii',$session_id,$session_id);
$stmt->execute();
}
$tempArray=array();
$result=$stmt->get_result();
如果($result->num_rows>0){
而($row=$result->fetch_assoc()){
if(!in_数组($row['to_id']。$row['from_id'],$tempArray)){
回声“
”; echo$row['from_id'].-“$row['to_id'..”..$row['msg'.-“$row['sent_time']; $assured_from_id=str_replace($session_id,null,$row['to_id'].$row['from_id']); ?>
也可以在你的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";
    }

    ?>


无法理解;)。你想在这里说什么,你可以用印地语或英式英语告诉我你的观点。你想在href中获得谁的ID?当我讨论另一个用户上次发送的消息时,如果我无法打开封面,因为它显示了我的ID。因此,我想让另一个用户知道我上次发送消息时的问题年龄未打开,但如果上次向我发送的邮件的url已打开,则为另一个用户。相同的结果获取您可以回复自己的邮件,但无法回复对方发件人的邮件。这是您的问题吗?我太困惑了,可以将您的代码发到info@socialcodia.commy代码问题,当我与其他用户停用时,如果我以la的身份发送消息st message it我的用户id显示在url上,但我希望讨论的其他用户id获得url我的id 1您可以检查输出图像我检查了兄弟,但相同的结果消息不用于扩展讨论;此对话已被取消。
<?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";
    }

    ?>