Mysqli Subquery with repeated variable and IN with Like

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. Well, i was looking for all post but nothing has worked. I tried REGEXP and similars but returns results that aren’t correct.

//I used asigned letters because you can understand better

$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 "....";
   }
}

On b1.id_book IN (?) I want something like this: b1.id_book IN like ?

There i put the code that works. I know how use Like, but im saying that code works when i tried on database query but on php, on change:

IN ( SELECT id_book_genre FROM Book b1, Genres_book g1 WHERE b1.id_book = g1.id_genre_book AND [b]b1.id_book LIKE ?[/b])
AND NOT ([b]b.id_book Like ?[/b]) GROUP BY b.name ORDER BY duplicated DESC");

$result->bind_param('ii', $book,$book);

I tried without “AND NOT (b.id_book Like ?)” and only bind 1 parameter but both returns 0 results.

Sorry for my english, I’m desperate I hope someone can help me out.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.