PHP SQL查询,逻辑解析结果

时间:2013-04-16 02:37:25

标签: php sql boolean logic

我正在尝试根据天气生成逻辑条件,或者不使用下面的代码在表格中生成值。回显的结果返回为[“0”]。我如何解析,所以php可以将值解释为布尔值?

$rowExists = mysql_query("SELECT EXISTS(SELECT 1 FROM table_name WHERE column_name = value)");

echo "result: ".json_encode(mysql_fetch_row($rowExists));

1 个答案:

答案 0 :(得分:0)

$result = mysql_query('SELECT COUNT(*) FROM table_name WHERE column_name = value') or die(mysql_error());
$count  = mysql_result($result, 0, 0);

if ($count > 0) {
    echo 'It exists!';
}