php mysqli 中的两个用户对话 URL

two users conversation URL in php mysqli

提问人: 提问时间:12/8/2019 更新时间:12/8/2019 访问量:71

问:

我正在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 会话 mysqli

评论

0赞 mufazmi 12/8/2019
无法理解;)。你想在这里说什么
0赞 mufazmi 12/8/2019
你可以用印地语或印地语告诉我你的观点。
0赞 Jonathan Thunberg 12/8/2019
您想在 href 中获得谁的 ID?
0赞 12/8/2019
当我讨论另一个用户的最后一条消息时,如果已经发送,我无法打开封面,因为它显示我的 ID,因此我想让另一个用户它到 URL
0赞 12/8/2019
当我发送最后一条消息时,我的问题没有打开,但是如果发送给我的最后一条消息,则另一个用户打开了URL。

答:

-1赞 Jonathan Thunberg 12/8/2019 #1

希望这次我能理解

这是我的代码:

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

评论

0赞 Samuel Liew 12/9/2019
评论不用于扩展讨论;此对话已移至 Chat
0赞 mufazmi 12/8/2019 #2

同时更改您的 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";
    }

    ?>

评论

0赞 12/8/2019
获得相同的结果
0赞 mufazmi 12/8/2019
您可以回复自己的邮件,但不能回复对方发件人的邮件。是你的问题吗?
0赞 mufazmi 12/8/2019
我太困惑了,你能把你的代码邮寄给我们吗 [EMAIL PROTECTED]
0赞 12/8/2019
我的代码问题,当我与其他用户讨论时,如果我发送了消息作为最后一条消息,我的用户 ID 显示在 URL 上,但我想讨论其他用户 ID 以获取 URL MY ID 1 您可以检查输出图像
0赞 12/8/2019
我检查了兄弟,但结果相同