while循环执行-1(mysql_fetch_assoc)

时间:2011-06-19 21:55:59

标签: php while-loop

简短而简单:我的PHP while ($R = mysql_fetch_asoc($sql)结果循环-1 ... 所以,当我得到4个结果时,它只显示3个, 有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:3)

造成这种情况的最常见原因是因为您在第一次来之前呼叫mysql_fetch_assoc($sql)

像这样:

$firstRow = mysql_fetch_assoc($sql);
while ($R = mysql_fetch_assoc($sql) {
   //> Dataset with -1 row
}

修复:

mysql_data_seek($query,0);
while ($R = mysql_fetch_assoc($sql) {

答案 1 :(得分:1)

补充@ yes123回答:

$R = mysql_fetch_assoc($sql);
// code that needs that first call to mysql_fetch_assoc()

do {
 //code
} while (($R = mysql_fetch_assoc($sql));