我已经创建了一个通知脚本,并且有一个名为notificationCenter.php的页面,管理员用户可以在其中查看所有通知。它将显示哪些用户阅读了哪些通知,发布时间和发布者。一切正常,唯一的问题是当我进入notificationCenter.php页面以查看所有通知时,该表未显示结果。但是我运行一条if语句来检查是否有任何结果,并且没有收到任何错误。这是我的代码,我确定我做过一些愚蠢的事情,但是我看不到它是什么,我将非常感谢您的帮助!。
//Get User ID
$id = $_SESSION['user_id'];
//Select * Notifications
$notQuery = $serviceConn->query("SELECT * FROM db759709251.notifications WHERE `not_viewedby` NOT LIKE '%$id%' ");
<h4>Nofication Center</h4>
<?php if($notQuery->rowCount()) { ?>
<table>
<thead>
<tr>
<th scope="col">Status</th>
<th scope="col">User</th>
<th scope="col">Notification</th>
<th scope="col">Date</th>
<th scope="col">Viewed By</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php
while ($row = $notQuery->fetch()) {
$notid = $row['not_id'];
$notUser = $row['not_user'];
$notMsg = $row['not_msg'];
$notStatus = $row['not_status'];
$notDate = $row['not_date'];
$notViewedby = $row['not_viewedby'];
?>
<tr>
<td style="background-color: <?php echo $statusColour; ?>" data-label="Status"><?php echo $notStatus; ?></td>
<td data-label="User"><?php echo $notUser; ?></td>
<td data-label="Notification"><?php echo $notMsg; ?></td>
<td data-label="Date"><?php echo $notDate; ?></td>
<td data-label="Viewed By"><?php echo $notViewedby; ?></td>
<td data-label="">
<form action="" method="POST">
<input type="hidden" name="notificationID" value="<?php echo $notid; ?>" >
<input type="hidden" name="notificationBy" value="<?php echo $notViewedby; ?>">
<input type="submit" name="read" value="Dismiss!">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php } else { ?>
<p>You currently have no notifications, please check back later.</p>
<?php } ?>
现在显然中间有很多HTML用于样式和布局,但是我认为它并不重要,因为它对表的输出没有任何影响。但是正如您所看到的,如果if语句应该打印没有通知并稍后再检查,从理论上讲不是这样,应该显示记录。