任何人都可以解释为什么最后一次查询总是返回1行。它应该返回多于1,因为数据库中有很多记录!PHP'IN'查询只返回1行
对不起我的英文不好
$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;
您应该使用mysql_fetch_assoc()来读取第二个查询结果,就像第一个查询结果一样。 – MarcinJuraszek 2012-04-13 16:42:59