计算和比较行查询Mysql PHP

时间:2016-03-21 17:43:44

标签: php mysql count

我是PHP的初学者,如果查询的所有行都正确,我需要你的帮助:打印一条消息,如果部分或全部不符合条件,则打印另一条消息。

我需要Qry和PHP sintaxis的帮助,我想我需要使用te COUNT,但我现在不知道该怎么做。

感谢。

我的表名:oder_product

+-----+-----+-----+-----+-----+------+
| id | item_id | shipping | delivery |
======================================
| 1  |    1    |   YES    |    NO    |  
======================================

======================================
| 2  |    2    |   YES    |   YES    | 
======================================
| 3  |    2    |   YES    |   YES    | 
======================================
| 4  |    2    |   YES    |   YES    | 
======================================
| 5  |    2    |   YES    |   YES    | 
======================================

======================================
| 6  |    3    |   YES    |    NO    | 
======================================
| 7  |    3    |   YES    |   YES    | 
======================================

SELECT * FROM oder_product WHERE shipping=’YES’ AND delivery=’YES’ AND item_id=‘2’;

PHP

If $result=all rows match;
Echo’ All Products match’;

else
Echo’ some products don’t match’;

1 个答案:

答案 0 :(得分:0)

$sql=SELECT * FROM oder_product WHERE shipping='YES' AND delivery='YES' AND item_id='2';
$result=mysqli_query($con,$sql);

使用mysqli_num_rows()查找号码

$rowcount=mysqli_num_rows($result);
if($rowcount>0){
echo 'All Products match';
}
else{
echo 'some products don’t match';
 }