I have a subquery that search all the genres that have an specific book, and the query makes it find all the books that have those genres of the subquery and it is creates a count of the times that repeat the same books and creates a new column of the counter. The orderly query remaining is based on books that are repeated more to less.
This query works but the problem comes when i tried to insert variable at server part with mysqli. I'm trying to do it for oriented objects but it does not return results.
$book = $get_id_book;
$book = "%$book%";
$result = $link->prepare ("SELECT b.name, COUNT(name) AS duplicated, c.arxive, t.type, t.name_type
FROM Books b, Covers c, Types t, Genres_book g
WHERE b.id_book = c.id_cover_book AND
b.id_book = g.id_genre_book AND
g.id_book_genre IN ( SELECT id_book_genre
FROM Book b1, Genres_book g1
WHERE b1.id_book = g1.id_genre_book AND
b1.id_book IN (?)) AND
NOT (b.id_book = ?)
GROUP BY b.name
ORDER BY duplicated DESC");
$result->bind_param('i', $book);
if($result->execute()){
$result->bind_result($name, $duplicated, $arxive, $type, $name_type);
while ($result->fetch()) {
echo "....";
}
}
What I have tried:
Well, i was looking for all post but nothing has worked. I tried REGEXP and similars but returns results that aren't correct.
On
b1.id_book IN (?)
I want something like this:
b1.id_book IN like ?
Sorry for my english, I'm desperate I hope someone can help me out.