我有一个查询,
$theresult = mysql_query("SELECT * FROM table WHERE column_b = ".$variable);
因此,这将生成一个结果列表,3 列。
我想做的是检查结果的任何行在 C 列中是否有"27"。
我不需要结果,只需要一个真/假..
谢谢!
嗨,
我想您想检查任何行的 c 列在获取结果 PHP 时是否具有值 27。然后
1.如果可以添加条件column_c = 27,则使用mysql_num_rows计算结果中的行数
$result = mysql_query("select * from table where column_b = ".$variable." AND column_c = 27") or die(mysql_error());
if($result){
if(mysql_num_rows($result) > 0){
echo "true";
}else{
echo "false";
}
}
2.如果您不想在 mysql 查询中更改,那么
$result = mysql_query("select * from table where column_b = ".$variable."") or die(mysql_error());
$exist = "false";
if($result){
while($row = mysql_fetch_array($result)){
if($row['column_c'] == 27){
$exist = "true";
}
}
}
echo $exit;
更改查询:
"SELECT * FROM table WHERE column_b = ".$variable." AND colc = 27"
SELECT COUNT(*) FROM table WHERE column_b = 'var' AND column_c = 27
这将返回匹配行数。如果没有匹配的行,则得到 0。
试试这个:
$theresult = mysql_query("SELECT * FROM table WHERE column_b = ".$variable . " AND column_c=27");
if (mysql_num_rows($theresult) == 0 ) echo "False/True";