[英]The data from my mysql database are not showing correctly
我該怎么做,它只顯示一個插入的所有消息,另一個問題是當用戶閱讀那里的消息時,下面的這部分代碼沒有顯示。 您可以在頁面底部找到完整的代碼。
用戶閱讀了新消息后,此代碼部分未顯示,但我不會顯示:
$newpm = '<div id="notificationTitle">Message</div>
<div id="notificationsBody" class="notifications">You have no new messages</div>';
完整代碼:
$newpm_sql = mysql_query("SELECT * FROM `pm`
WHERE `to` = '". $_SESSION['id'] ."'
ORDER BY `id` DESC") or die(mysql_error());
if (mysql_num_rows($newpm_sql) == 0) {
$newpm = '<div id="notificationTitle">Message</div>
<div id="notificationsBody" class="notifications">You have no new messages</div>';
} else {
while ( $row = mysql_fetch_array( $newpm_sql )) {
$from_sql = mysql_query("SELECT * FROM `members`
WHERE `id` = '". $newpm_sql['from'] ."'")
or die(mysql_error());
$from = mysql_fetch_array($from_sql);
if ($row['status'] == 0) {
$newpm = '<div id="notificationTitle">Message</div>
<div id="notificationsBody" notifications">
<b><a href="page.php?name=profile&id='. $row['from'] .'">'. $row['subject'] .'</a></b><br> '. $row['text'] .'
'</div>';
}
}
}
首先運行這個:
SELECT * FROM `pm` WHERE `to` = '<your SESSION ID>'
ORDER BY `id` DESC
看看這是否會返回一些東西。
你也可以這樣做:
var_dump(mysql_num_rows($newpm_sql));die;
在第一行運行這個 mysql_query 之后,看看它是否返回了你期望的東西。
而且,您可以切換到 PDO - 您不會后悔,因為您現在使用的是舊的 php 函數。
我看到了我上次錯過的錯誤。
這個說法
$newpm = '<div id="notificationTitle">Message</div>
<div id="notificationsBody" class="notifications">You have no new messages</div>';
正在一個while
循環中運行,因此您應該使用.=
而不僅僅是一個=
將這些多次迭代連接到$newpm
while ( $row = mysql_fetch_array( $newpm_sql )) {
$from_sql = mysql_query("SELECT * FROM `members`
WHERE `id` = '". $newpm_sql['from'] ."'")
or die(mysql_error());
$from = mysql_fetch_array($from_sql);
if ($row['status'] == 0) {
//$newpm = '<div id="notificationTitle">Message</div>
newpm .= '<div id="notificationTitle">Message</div>
<div id="notificationsBody" notifications">
<b>
<a href="page.php?name=profile&id='. $row['from'] .'">'. $row['subject'] .'</a>
</b>
<br> '.
$row['text'] .'
'</div>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.