一旦我从mysql改成pdo,我就不能让我的计数工作了。我不知道该怎么办。
<tr>
<td style="width: 125px">
<a href="SystemsTechsPages/xgrh/xgrhCompleted1.php" target="_top">xgrh</a>
</td>
<td style="width: 125px" align="center">
<a href="SystemsTechsPages/xgrh/xgrhCompleted1.php" target="_top">
<?php
$stmt = $db->prepare("
SELECT COUNT(*) FROM WHERE requests status='Completed' AND compDT=Curdate() AND compUser='xgrh'
");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['COUNT(*)'];
}
?>
</a>
</td>
</tr>
最佳答案
您应该更改查询:
SELECT COUNT(*) AS rows_cnt FROM table WHERE status='Completed' AND compDT=Curdate() AND compUser='xgrh'
然后:
像这样使用:
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo $row['rows_cnt'];
}