0

I have tryed to solve this but it has me stuck. any ideas help much appreciated. The book id is getting send to the url. url looks like /bookinfo.php?bookid=1

if(isset($_GET['bookid'])){
    $id = preg_replace('#[^0-9]#i','', $_GET['bookid']);
    $sql = "SELECT DISTINCT bk.title AS Title, bk.year AS Year, bk.publisher AS Publisher, aut.authorname AS Author cat.category AS Category
         FROM book bk 

         JOIN book_category bk_cat 
         ON bk_cat.book_id = bk.bookid

         JOIN categories cat 
         ON cat.id = bk_cat.category_id

         JOIN books_authors bk_aut 
         ON bk_aut.book_id = bk.bookid

         JOIN authors aut
         ON aut.id = bk_aut.author_id

         WHERE bk.bookid='$id' LIMIT 1";

    $productCount = mysql_num_rows($sql);
    if($productCount>0){
        while($row =mysql_fetch_array($sql)){
            $bookTitle = $row["Title"];
            $bookYear = $row["Year"];
            $bookPublisher = $row["Publisher"];
            $bookcopies = $row["copies"];
            $bookAvailableforreserve = $row["availableforreserve"];
            $bookDescription = $row["description"];
            $bookAuthor = $row["Author"];
            $bookCategory = $row["Category"];


        }
    }

?>
1

3 Answers 3

1

Got it the problem was being caused by a miss , before the start of cat.category AS Category

Thanks

Sign up to request clarification or add additional context in comments.

Comments

0

You didn't execute your query that's why mysql_num_row() give you the error

$sql = mysql_query("SELECT DISTINCT bk.title AS Title, bk.year AS Year, bk.publisher AS Publisher, aut.authorname AS Author cat.category AS Category
     FROM book bk 

     JOIN book_category bk_cat 
     ON bk_cat.book_id = bk.bookid

     JOIN categories cat 
     ON cat.id = bk_cat.category_id

     JOIN books_authors bk_aut 
     ON bk_aut.book_id = bk.bookid

     JOIN authors aut
     ON aut.id = bk_aut.author_id

     WHERE bk.bookid='$id' LIMIT 1");

$productCount = mysql_num_rows($sql);

1 Comment

hey fabio thank for helping, just tried that still same result :( anything else you can see
0

You need to do a mysql_query() on your select string in order to do use the mysql_num_rows() function.

$sql = "SELECT DISTINCT bk.title AS Title, bk.year AS Year, bk.publisher AS Publisher, aut.authorname AS Author cat.category AS Category
 FROM book bk 

 JOIN book_category bk_cat 
 ON bk_cat.book_id = bk.bookid

 JOIN categories cat 
 ON cat.id = bk_cat.category_id

 JOIN books_authors bk_aut 
 ON bk_aut.book_id = bk.bookid

 JOIN authors aut
 ON aut.id = bk_aut.author_id

 WHERE bk.bookid='$id' LIMIT 1";

$sql_query = mysql_query($sql);

$productCount = mysql_num_rows($sql_query);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.