MySQL Forums
Forum List  »  PHP

Basic Join query does not work
Posted by: Alkan Gündüz
Date: June 26, 2021 07:17AM

Hello,

i started my MySQL/PHP experience right now and got in struggle with PHP and MYSQL. I hope someone can give me a answer.

i have two tables:

First table: recommendations with the columns
id--product--username--vote
1---1------------XXXX---------1
2---1------------XXXY---------2
3---1------------XXYY---------1
4---2------------XXXX---------2

Second table: products with the columns
id--name----author
1---PRODA--author1
2---PRODB--author2
3---PRODC--author3
4---PRODD--author4

now i want to count the row where the id match the product, and where username match the author to count every vote with 1

i try it with the following SQL query:

$member = $_GET['user'];

$getu = $connect->prepare("SELECT * FROM `users` WHERE `username` = :username");
$getu->execute([':username' => $member]);
$pu = $getu->fetchObject();

to get the User in the profil

and my query to count the row is:

$getposb = $connect->prepare("SELECT * FROM 'recommendations' LEFT JOIN 'products' ON 'recommendations.product'='products.id' WHERE 'products.author' = ':username' AND 'vote' = ':pos'");
$getposb->execute([':username' => $pu->username, ':pos' => 1]);

and with <?= $getposb->rowCount(); ?> i count the rows.

i hope someone can find my mistake its my first time using JOIN.

Options: ReplyQuote


Subject
Written By
Posted
Basic Join query does not work
June 26, 2021 07:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.