我正处于开始理解PHP和MySQL的阶段,但我陷入困境。我一直在研究一下来自developphp.com的教程,其中Shawn的WI正在构建一个消息系统
https://www.youtube.com/playlist?list=PLgsYR-L3Uwbps9E-xIQPajQOiZVbOo6lr
我正在尝试重新设计教程,以满足我的需求。我已经建立了一个名为pm_inbox.php的邮件页面,它工作正常,它给了我以DESC顺序发送给我的邮件。
pm_inbox.php
$sql = "SELECT pm.*, u.avatar, u.country
FROM pm AS pm
LEFT JOIN users AS u ON u.username = pm.sender
WHERE (pm.receiver='$u' AND pm.parent='x' AND pm.rdelete='0')
OR (pm.sender='$u' AND pm.sdelete='0' AND pm.parent='x' AND pm.hasreplies='1')
ORDER BY senttime DESC";
$query = mysqli_query($db_conx, $sql);
$statusnumrows = mysqli_num_rows($query);
// Gather data about parent pm's
if($statusnumrows > 0){
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$pmid = $row["id"];
//div naming
$pmid2 = 'pm_'.$pmid;
$wrap1 = 'pm_message_wrap_'.$pmid;
//button naming
$btid2 = 'bt_'.$pmid;
//textarea naming
$rt = 'replytext_'.$pmid;
//button naming
$rb = 'replyBtn_'.$pmid;
$receiver = $row["receiver"];
$sender = $row["sender"];
$subject = $row["subject"];
$message = $row["message"];
$time = $row["senttime"];
$rread = $row["rread"];
$sread = $row["sread"];
$avatar = $row["avatar"];
$country = $row["country"];
// Start to build our list of parent pm's
$mail .= '<div id="'.$wrap1.'" class="pm_message_wrap">';
$mail .= '<table id="inboxMailMessages" width="100%" align="center" cellpadding="2">
<tr>
<td width="6%"><input name="toggleAll" id="toggleAll" type="checkbox"/></td>
<td width="19%"><a href="user.php?u='.$sender.'" title="'.$sender.'"><img src="user/'.$sender.'/'.$avatar.'"width=100" height="100" border="0" /></a></td>
<td width="75%">
<div class="inboxmailRollover">
<p class="mailboxp">Subject: ' .$subject. '<br></p>
<p class="mailboxp"><a href="user.php?u=' . $sender . '">From:'.$sender. '</a><br></p>
<p class="mailboxp"><a href="inboxMain.php?u=' . $u . '">' .$country. '</a><br></p>
<p class="mailboxp">' .$message. '</p>
</div>
</td>
</tr>
</table>';
$mail .= '<hr>';
$mail .= '</div>';
我想要做的是当有人点击pm_inbox.php上的国家/地区链接时,它会将他们带到另一个名为inboxMain.php的页面,在该页面中,它将在已发送邮件的容器中显示人员详细信息。发件人,主题和国家。
我在pm_inbox.php上有4封邮件,人们已经发给我了。当我按下国家链接时,它会将我带到inboxMain.php,但不是向我显示向我发送邮件的人员详细信息,而是在4个单独的容器中显示所有4个人的详细信息。我知道这是inboxMain.php上的SQL查询问题,但无法解决它。我想知道是否有人可以帮助我。
inboxMain.php
$sql = "SELECT pm., u.avatar, u.country
FROM pm AS pm
LEFT JOIN users AS u ON u.username = pm.sender
WHERE pm.id='$pmid' AND pm.sender='$u' AND pm.sdelete='0' AND pm.parent='x'";
$query = mysqli_query($db_conx, $sql);
$statusnumrows = mysqli_num_rows($query);
// Gather data about parent pm's
if($statusnumrows > 0){
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$pmid = $row["id"];
//div naming
$pmid2 = 'pm_'.$pmid;
$wrap2 = 'reply_profile_wrap'.$pmid;
//button naming
$btid2 = 'bt_'.$pmid;
//textarea naming
$rt = 'replytext_'.$pmid;
//button naming
$rb = 'replyBtn_'.$pmid;
$receiver = $row["receiver"];
$sender = $row["sender"];
$subject = $row["subject"];
$message = $row["message"];
$time = $row["senttime"];
$rread = $row["rread"];
$sread = $row["sread"];
$avatar = $row["avatar"];
$country = $row["country"];
// Start to build our list of parent pm's
$reply_profile .= '<div id="'.$wrap2.'" class="reply_profile_wrap">';
$reply_profile .= '<table id="replyProfile" width="100%" border="0">
<tr>
<td width="19%"><a href="user.php?u='.$sender.'" title="'.$sender.'"><img src="user/'.$sender.'/'.$avatar.'"width=75" height="75" border="0" /></a></td>
<td>
<p class="replyProfilep">Subject: ' .$subject. '<br></p>
<p class="replyProfilep"><a href="user.php?u=' . $sender . '">From:'.$sender. '</a><br></p>
<p class="replyProfilep">Country: ' .$country. '</p>
</td>
</tr>
</table>';
$reply_profile .= '</div>';
答案 0 :(得分:0)
在该国家/地区设置一个获取特定pm.id
的链接。
<p class="replyProfilep"><a href="mail.php?id=' . $pmid . '">Country: ' .$country. '</a></p>
然后在mail.php
中,您可以使用以下查询:
$pmid = $_GET['id'];
$sql = "SELECT pm.*, u.avatar, u.country
FROM pm AS pm
LEFT JOIN users AS u ON u.username = pm.sender
WHERE pm.id = $pmid";