如何在PDO中设置IF ELSE条件?
如果有 faces ='N'的记录,我希望能够回显结果。或回声'空'。
$query = $db->prepare('SELECT student, subject FROM my_db WHERE faced = ? ORDER BY RAND() LIMIT 1');
$array = array('N');
$query->execute($array);
if ($query>0){
$result = $query->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
} else {
echo 'Empty';
}
答案 0 :(得分:0)
您可以在检查前执行提取:
$query->execute($array);
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0){
var_dump($result);
} else {
echo 'Empty';
}
答案 1 :(得分:0)
你去!通过查询来完成:
SELECT
Student,
Subject,
Max(CASE When faced ='N' then faced else 'Empty' End) as Faced
FROM my_db
group by student