I am new to PHP and SQL. I am trying to count how many times product is liked and all the products a particular user has liked.But couldn't get the desired results.
I have 3 tables.
product table: pro_id pro_info pro_price
user table: id username password
and pro_likes table: id user product
In pro_likes table "user" and "product" columns are foreign keys referring to user(id) and product(pro_id) respectively. How can I find out how many times a particular product has been liked and which product a particular user has liked?
I tried the following to find out the former but it return the counts for all the products, not a single one.
$q="SELECT
COUNT(pro_likes.product) AS likes
FROM pro_likes
LEFT JOINT products
ON pro_likes.product = products.pro_id";
$r=mysqli_query($con,$q);
$r1=mysqli_fetch_assoc($r);
echo $r1['likes'];
Can anyone please help?