我目前正忙于在 PDO 中获取论坛系统。我已经完成了索引,我现在正忙于该类别,但以一种奇怪的方式,我没有收到该类别。当我在 category.php?id=1 时,它说该类别不存在。以下代码是接收类别id的部分
<?php
$sql = $db->query("SELECT
cat_id,
cat_name,
cat_description
FROM
categories
WHERE
cat_id = " . $_GET['id']);
$result = $sql->rowCount();
if(!$result)
{
echo 'The category could not be displayed, please try again later.';
}
else
{
if($sql || ($result== 0))
{
echo 'This category does not exist.';
}?>
它显示了这个类别的福特不存在线。我不知道有什么问题,表格是正确的。这是桌子。http://sqlfiddle.com/#!2/8d1c4。
我是 PDO 的初学者,所以也许这只是一个简单的错误,因为我不知道。
对于想知道答案的人。这是我现在使用的脚本:
<?php
//first select the category based on $_GET['cat_id']
$sql = $db->prepare('SELECT cat_id, cat_name, cat_description
FROM categories WHERE cat_id = :catid');
$sql->bindParam(':catid', $_GET['id'], PDO::PARAM_INT);
$sql->execute();
$result = $sql->rowCount();
if($result === FALSE){
echo 'The category could not be displayed, please try again later.';
}
elseif(count($result) === 0){
echo 'This category does not exist.';
}
else{