Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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


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.
Posted
Comments
santa_oscuro 17-Aug-18 21:22pm    
here 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:

Hide   Copy Code
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... but if i try at database directly change "?" for the numbers, works perfectly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900