0

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

<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 的 John,我想在下一页将其保存为 pmid 并将消息插入到 table'pm' 中,其中 from id = Session id 并且 to 是 pmid。即 4 谁是约翰..

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

提前致谢 !

4

2 回答 2

0

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

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

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

于 2013-09-19T14:11:26.350 回答
0

在此处尝试您的代码....

    <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>

并在 pm.php 页面上

echo $_GET['pid'];  //OR echo $_REQUEST['pid'];  
于 2013-09-19T14:17:52.687 回答