来自 sql 查询结果的 PHP 会话


PHP session from sql query Result

这个问题可能有点愚蠢...我正在尝试实现一个聊天系统,其中我从这段代码中获取用户..

<table>
    <tr>
        <th>Id</th>
        <th>Username</th>
        <th>Email</th>
        <th>Status</th>
    </tr>
<?php
//We get the IDs, usernames and emails of users
$req = mysql_query('SELECT id, username, email , Online from users');
while($dnn = mysql_fetch_array($req))
{
?>
    <tr>
        <td class="left"><?php echo $dnn['id']; ?></td>
        <td class="left"><a href="profile.php?id=<?php echo $dnn['id']; ?>"><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></a></td>
        <td class="left"><?php echo htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php if(($dnn['Online'])=="online") {echo'<img src="default/images/online.png" width="10" height="10" align="center" >';} ?></td>
    </tr>
<?php
}
?>
</table>

而现在,当用户被点击时,它会转到pm.php,我还没有编码。

如何设置在上一页中被点击的用户的变量"PMID"?

例如:- 我点击了 约翰 ,其 id 为 4 ,我想在下一页将其另存为 pmid,并将消息插入表'pm',其中 from id = 会话 id,to 是 pmid。 即 4 谁是约翰.

我想让你解释一下这个概念!

提前感谢!

只需像这样向表中添加另一列

<td class="left"><?php echo '<a href="pm.php?pmid=' . $dnn['id'] . '">Message this user</a>'; ?></td>

现在,当您单击该链接时,用户 id 将成为 url 中的一个参数。然后,您可以使用$_GET['pmid']在下一页上检索该 ID

在这里试试你的代码....

    <table>
        <tr>
            <th>Id</th>
            <th>Username</th>
            <th>Email</th>
            <th>Status</th>
        </tr>
    <?php
    //We get the IDs, usernames and emails of users
    $req = mysql_query('SELECT id, username, email , Online from users');
    while($dnn = mysql_fetch_array($req))
    {
    ?>
        <tr>
            <td class="left"><?php echo $dnn['id']; ?></td>
            <td class="left"><a href="profile.php?id=<?php echo $dnn['id']; ?>"><?php echo htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); ?></a></td>
            <td class="left"><?php echo htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); ?></td>
            <td class="left"><?php if(($dnn['Online'])=="online") {echo'<img src="default/images/online.png" width="10" height="10" align="center" >';} ?></td>
            <td class="left"><a href="pm.php?pid=<?php echo $dnn['id']; ?>">Go to Pm page</a></td>
        </tr>
    <?php
    }
    ?>
</table>

在下午.php页面上

echo $_GET['pid'];  //OR echo $_REQUEST['pid'];