MySQL EXISTS返回1或0

时间:2012-11-01 13:38:15

标签: php mysql select

如何为我的选择查询返回1或0为true和false?我已经尝试了fetch_assoc,数组等的每个组合。它通常返回null,这没有意义。

$querydetails = "select exists (select * from customer_det where id = $uid)";
$resultdetails = mysql_query($querydetails) or die(mysql_error());
while ($row = mysql_fetch_assoc($resultdetails)) {
    $resultdetails1 = $row[0];
}

这是我查询的最新版本。我猜这不是一个数组,但如果没有要命名的行,我不知道如何提取值?

这是我之前帖子的帖子问题:MySQL Update WHERE

3 个答案:

答案 0 :(得分:4)

SELECT IF(EXISTS(...),1,0) AS result

答案 1 :(得分:2)

简单使用COUNTIF

SELECT IF(COUNT(*) = 0, 0, 1)
FROM table1
WHERE s = 2

答案 2 :(得分:-1)

我愿意:

select * from customer_det where id = $uid LIMIT 1

您将获得1行或0行。

相关问题