如何在PHP中将mysql_query设为true或false变量?

时间:2012-03-11 03:33:44

标签: php sql

我希望sql_query能够查看表格,并在$变量中告诉我项目是否在表格中。

我是不是错了?

$string = mysql_query("SELECT * FROM Table WHERE Column = 'item'");

if ( $string == true ) {
    $roger = "Found it!";
    } else {
    $roger = "Sorry dude!";
    }

echo $roger;

1 个答案:

答案 0 :(得分:3)

使用mysql_num_rows() http://www.php.net/manual/en/function.mysql-num-rows.php

$resource = mysql_query("SELECT * FROM Table WHERE Column = 'item'");

if ( mysql_num_rows($resource) > 0 ) {
    $roger = "Found it!";
} else {
    $roger = "Sorry dude!";
}

echo $roger;