-2

i just made user rating system using pdo for my book store project, but the comments are not based on id. how do I show the comments according to book id?

here's my code.

$query = "
    SELECT review.pengguna_id, review.buku_id, review.rating, review.komentar, review.tanggal, pengguna.username
    FROM review 
    INNER JOIN buku ON review.buku_id = buku.id 
    INNER JOIN pengguna ON review.pengguna_id = pengguna.id
    WHERE review.buku_id = buku_id
    ORDER BY review.id DESC;
";

when i use review.buku id = buku_id, it shows all comments no matter what the id.

Nick
  • 123,192
  • 20
  • 49
  • 81
Auriga
  • 1
  • Please use standard grammar & punctuation & format your post reasonably. Read the edit help re inline & block formats for code & quotations. – philipxy May 21 '22 at 05:37
  • 1
    That's because `review.buku_id = buku_id` is equivalent to `review.buku_id = review.buku_id` (since `buku_id` only occurs in `review`) which is always true. You need to use a condition which takes an input of an `id` value (e.g. using a prepared statement use `review.buku_id = :buku_id` and pass the appropriate value to the `:buku_id` parameter by binding or directly when you execute the query – Nick May 21 '22 at 06:03

0 Answers0