1
$sql = "SELECT `description`,`auction_id` FROM `auctions` WHERE `description` REGEXP  '(97(8|9))?[[:digit:]]{9}([[:digit:]]|X)'";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
$row = mysql_fetch_row($result);
echo "$row[1]";

有什么理由echo "$row[1]";返回每隔一行?我得到的结果是这样的,我试图得到每一行

4

5 回答 5

2

要真正回答您的问题,为什么会发生

$row = mysql_fetch_assoc($result); //this advances the internal data pointer by 1
$row = mysql_fetch_row($result); //this advances it by 1 more

两者都在循环的每次迭代中执行。 你应该使用一个,而不是两个。

此外,您不应该在新代码中使用mysql_*函数,因为它已被弃用。如评论中所述,使用 PDO 或 MySQLi。

于 2013-01-24T08:39:08.230 回答
0

如果查询在 phpmyadmin 中正常工作,那么您可以使用

while ($row = mysql_fetch_assoc($result)) {
echo $row['description'];
}

或者

$row = mysql_fetch_row($result);
echo $row[1];

或者

while ($row = mysql_fetch_array($result)) {
echo $row['description']; //or
echo $row[1];
}
于 2013-01-24T08:39:55.770 回答
0

您正在调用 fetch 函数两次,因此它似乎每次都跳过一行。

while ($row = mysql_fetch_assoc($result)) {
$row = mysql_fetch_row($result);    //This is not needed
echo "$row[1]";
}

应该

while ($row = mysql_fetch_assoc($result)) {
echo $row[1];
}
于 2013-01-24T08:35:11.653 回答
0

而不是让循环为:

while ($row = mysql_fetch_assoc($result)) {
    $row = mysql_fetch_row($result);

利用:

while ($row = mysql_fetch_assoc($result)) {
于 2013-01-24T08:35:20.440 回答
0

你应该这样使用。

while ($row = mysql_fetch_assoc($result)) {
  $desc[] = $row['description'];
}
于 2013-01-24T08:36:09.723 回答