Can anyone explain me why the last query returns always 1 row. it should return more than 1 because there’re a lot of records in the database!
Sorry for my bad english
$query=mysql_query("SELECT book_id FROM ".DB_PREF."books_cats_list WHERE cat_id='".$cat."'");
if($row=mysql_num_rows($query))
{
//fetching all books from $cat category
for($i=0; $fetch=mysql_fetch_assoc($query); $i++)
{
$records[$i]=$fetch['book_id'];
}
//Joining all records in a string for next query
$records=implode(",",$records);
//returning num rows if there're book_id records in $records array
$query=mysql_query("SELECT * FROM ".DB_PREF."books WHERE book_id IN ('".$records."')");
$rows=mysql_num_rows($query);
echo $rows;
Your query is going to look like this:
Note how inside the
IN, it’s all one string. This one string will be converted to an int. This happens by stopping at the 1st non-number character. So, the query becomes:Try to remove the single quotes inside the
IN.NOTE: If your values aren’t ints, try changing the the
implodeto:implode("','",$records), and keep the quotes inside theIN.