基本上,我有一张table叫 requests
,在该表中有一列名为 status
. 默认情况下, status
设置为挂起,但也可以设置为已批准或已拒绝。
我试图显示状态设置为挂起的行中的数据,但不显示已批准或已拒绝的行。
我该怎么做?
我的pdo声明:
try{
$statement = $db->query("SELECT * FROM requests");
$requests = $statement->fetchAll(PDO::FETCH_ASSOC);
}catch (PDOException $ex){
$result = flashMessage("An error occurred: " .$ex->getMessage());
}
显示数据的页面:
<tbody>
<tr>
<?php if(isset($request['status'] === 'pending')): ?>
<th scope="row"><?= $request['id']; ?></th>
<td><?= $request['username']; ?></td>
<td><?= $request['artist']; ?></td>
<td><?= $request['day']; ?></td>
<td><?= $request['venue']; ?></td>
<td><?= $request['city']; ?></td>
<?php else: ?>
<? # do nothing ?>
<?php endif: ?>
</tr>
</tbody>
我当前的代码包含导致500错误的页面。
谢谢您!
2条答案
按热度按时间0qx6xfy61#
我认为500错误是由两个问题造成的,第一个问题:
检查php文档中的替代控制结构-应该是
那么,这个:
不是如何限制你的结果只有那些“待定”状态。
isset
只接受变量,给它一个表达式$request['status'] === 'pending'
是另一个分析错误。isset
仅对未设置或设置为的变量返回falsenull
.但这并不重要,因为您应该在查询中按状态进行筛选。只需添加一个where子句,并在php代码中去掉该检查。
krugob8w2#
您很可能得到错误500,因为您没有终止if语句。你需要一个分号。