mysql did not like your query: 'SELECT COUNT(DISTINCT(books.id)) AS cnt FROM books JOIN JOIN book_category ON book_category.bookid = books.id JOIN categories ON book_category.categoryid = categories.id WHERE ( books.published = 1 ) AND ( books.price <= 5.00 OR books.readerSetsPrice = 1 ) AND ( books.coverImg != '' ) ', err= You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN book_category ON book_category.bookid = books.id JOIN categories ON book_ca' at line 1