我已经写了代码来搜索数据。但是,当我运行代码时,它没有显示任何错误,也没有获取任何数据。谁能帮我找出问题所在?
这里是我的密码
<?php
$db = new PDO('mysql:dbname=mypro_bms;host=localhost', 'root', '');
$people = [];
if (!empty($_GET['p'])) {
$count='count';
$sum='sum';
$stmt=$db->prepare("SELECT passport_IC,count(*) as count,sum(blood_bag) as sum FROM donate GROUP BY passport_IC where passport_IC like :passport_IC");
$stmt->execute([
':passport_IC' => '%' . $_GET['p'] .'%',
':count'=> $count,
':sum' => $sum,
]);
$people = $stmt->fetchAll(PDO::FETCH_OBJ);
}
?>
<table class="table table-bordered">
<tr>
<th><center> passport </center></th>
<th><center> Donation Completed</center></th>
<th>blood donated</th>
<th><center> Percentage</center></th>
</tr>
<?php foreach($people as $donors): ?>
<tr>
<td><center><b><font color="black"><?= $donors->passport_IC; ?></font></b></center></td>
<td><center><b><font color="black"><?= $donors->count; ?>*Times*</font></b></center></td>
<td><center><b><font color="black"><?= $donors->sum; ?>ml</font></b></center></td>
</tr>
<?php endforeach; ?>
</table>
答案 0 :(得分:0)
您的查询错误。分组依据应在where子句之后。
SELECT passport_IC,count(*) as count,sum(blood_bag) as sum FROM donate where passport_IC like :passport_IC GROUP BY passport_IC