我希望sql_query能够查看表格,并在$变量中告诉我项目是否在表格中。
我是不是错了?
$string = mysql_query("SELECT * FROM Table WHERE Column = 'item'");
if ( $string == true ) {
$roger = "Found it!";
} else {
$roger = "Sorry dude!";
}
echo $roger;
答案 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;