mysql_fetch_row每隔一行返回一次?

时间:2013-01-24 08:33:17

标签: php mysql

$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]";每隔一行返回的原因是什么?我得到的结果就是这样,我试图获得每一行

5 个答案:

答案 0 :(得分: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。

答案 1 :(得分:0)

您正在调用两次获取功能,因此每次都会跳过一行。

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];
}

答案 2 :(得分:0)

而不是将循环设为:

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

使用:

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

答案 3 :(得分:0)

你应该这样使用。

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

答案 4 :(得分: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];
}
相关问题