[英]php, check if a result is in second column of mysql result
i have a query, 我有一个疑问,
$theresult = mysql_query("SELECT * FROM table WHERE column_b = ".$variable);
so this will produce a list of results, 3 columns. 因此这将产生3列结果列表。
what i want to do is check if any of the rows of the result have "27" in column C. 我想做的是检查结果的任何行在C列中是否有“ 27”。
i dont need the results, just a true/false.. 我不需要结果,只是一个对/错。
thank you! 谢谢!
更改查询:
"SELECT * FROM table WHERE column_b = ".$variable." AND colc = 27"
SELECT COUNT(*) FROM table WHERE column_b = 'var' AND column_c = 27
That returns the number of matching rows. 返回匹配的行数。 If there are no matching rows, you'll get 0.
如果没有匹配的行,您将得到0。
Try this: 尝试这个:
$theresult = mysql_query("SELECT * FROM table WHERE column_b = ".$variable . " AND column_c=27");
if (mysql_num_rows($theresult) == 0 ) echo "False/True";
Hi i think you want to check that column c of any row has value 27 or not in fetching result PHP..then 嗨,我认为您想检查任何行的c列是否在获取结果PHP..then中都具有值27
1.If you can add condition column_c = 27 then use mysql_num_rows for count number of rows in result 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.If you not want to change in mysql query then 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.