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"];


        }
    }

?>
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Shay Young
  • 207
  • 3
  • 11
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – Bojangles Mar 18 '14 at 22:10

3 Answers3

1

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

Thanks

Shay Young
  • 207
  • 3
  • 11
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);
Fabio
  • 23,183
  • 12
  • 55
  • 64
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);
Alfonse
  • 732
  • 1
  • 6
  • 7