0

你能解释一下为什么当我尝试这个查询时它只返回一半的行吗?

例如,如果 $records 由 4 个值组成,它只会从 DB 中获取第 1 行和第 3 行。

怎么了?

                $query=mysql_query("SELECT * FROM ".DB_PREF."books WHERE book_id IN ('".$records."')");
                while($fetch=mysql_fetch_assoc($query))
                {
                    global $book_id, $book_title, $book_description, $book_author_id, $book_author_name, $book_author_surname;
                    $book_id=$fetch['book_id'];
                    $book_title=$fetch['book_title'];
                    $book_description=$fetch['book_description'];
                    $book_author_id=$fetch['book_author_id'];
                    $query=mysql_query("SELECT * FROM ".DB_PREF."profiles WHERE user_id='".$book_author_id."'");
                    $fetch=mysql_fetch_assoc($query);
                    $book_author_name=$fetch['user_name'];
                    $book_author_surname=$fetch['user_surname'];
                    getModule('htmlmodule...');
                }
4

2 回答 2

2

你在循环中覆盖你的 $fetch 变量吗?也许尝试:

$fetch2=mysql_fetch_assoc($query);

或者,更好的是,在您的 SQL 中使用连接:

$query=mysql_query("SELECT * FROM ".DB_PREF."books LEFT JOIN ".DB_PREF."profiles ON book_author_id = user_id WHERE book_id IN ('".$records."')");

然后从那个单一的查询中得到你想要的一切。

于 2012-04-13T17:24:18.263 回答
0

我做的时候

mysql_select_db($database_lolx, $lolx);
$query_Recordset1 = "SELECT * FROM person";
$Recordset1 = mysql_query($query_Recordset1, $lolx) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
<table border="1">
  <tr>
    <td>id</td>
    <td>emal</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['id']; ?></td>
      <td><?php echo $row_Recordset1['emal']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
于 2012-04-13T17:27:41.263 回答