我正在尝试创建社交网络并在网站上添加通知栏,但代码未加载数据库中的数据。
$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">Meddelande</div>
<div id="notificationsBody" class="notifications">
Du har inga meddelanden!
</div>
';
} else {
while ( $newpm = mysql_fetch_array( $newpm_sql )) {
$from_sql = mysql_query("SELECT * FROM `members`
WHERE `id` = '". $newpm['from'] ."'")
or die(mysql_error());
$from = mysql_fetch_array($from_sql);
if ($newpm['status'] == 0) {
$newpm = '<div id="notificationTitle">Meddelande</div>
<div id="notificationsBody" notifications">'.
$newpm['subject'] .' '. $newpm['from'] .
'</div>';
}
}
}
答案 0 :(得分:1)
您正在使用变量field.SetValue(someObject, someValue);
几乎所有内容,因此会破坏其中所持有的内容。
在第二个查询中使用新变量,我在下面使用$newpm
作为示例
$row
此外,您不应该使用
$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">Meddelande</div> <div id="notificationsBody" class="notifications">Du har inga</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">Meddelande</div> <div id="notificationsBody" notifications">'. $row['subject'] .' '. $row['from'] . '</div>'; } } }
数据库访问扩展,它已被弃用,即将被删除。在您明显学习的过程中,请花时间学习mysql_
扩展程序或mysqli_
扩展程序。请参阅此方法以获取一些帮助,以确定您更喜欢Why shouldn't I use mysql_* functions in PHP?