当客户和产品名称匹配时显示“是”,如果不显示“否”。
shopping cart table
---------------------------
id|product name | customer
-----------------------------
1 |book | Tomic
2 |pencil | Tomic
3 |shoe | Jasper
-------------------------------
product name|
--------------------------
book | add to cart
---------------------------
当Tomic(客户)点击添加到购物车显示“是”时,如果Jasper(客户)点击添加到购物车显示“否”
if(isset($_POST['submit1']))
{
$customer = $_SESSION['login_user'];
$res2 = mysqli_query($mysqli,"SELECT * FROM shopping_cart where product_name='$product_name'");
while($row2=mysqli_fetch_array($res2))
{
if($customer==$row2['customer'])
{
echo "yes";
}
else
{
echo "no";
}
}
}
答案 0 :(得分:1)
更改yes
或no
条件
"SELECT * FROM shopping_cart where product_name='$product_name' and customer='$customer'"
您可以使用mysqli_num_rows();
$data=mysqli_num_rows($res2);
if($data>0){
echo "yes";
}
else{
echo "no";
}