Results 1 to 1 of 1

Thread: Mysqli Subquery that works on database but not on PHP

  1. #1
    Join Date
    Aug 2018
    Beans
    1

    Mysqli Subquery that works on database but not on PHP


    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
    "....";
    }
    }
    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 b1.id_book LIKE ?)
    AND NOT(b.id_book Like ?)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.
    Last edited by santa-oscuro; August 18th, 2018 at 03:16 AM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •