我正试图将我的一个网页从mysql命令更新到mysqli,除了记录的输出外,其他一切都正常。它跳过了第一行。应该有124条记录,我用验证
$NumCols = $RecordSet->num_rows;
Print($NumCols . "<br/>");
然而,只有123条记录使用以下代码打印:
// Fill the first row of the table with the field names
$row = mysqli_fetch_assoc($RecordSet);
foreach($row as $column => $value) {
Print("<td>" . $column . "</td>");
}
Print("</tr>");
// Fill the remaining rows of the table with the values
// This code is dropping the first result
$Pos = 1;
While($row1 = $RecordSet->fetch_assoc())
{
Print("<tr><td>$Pos</td>");
foreach($row1 as $column => $value) {
Print("<td>" . $value . "</td>");
}
Print("</tr>");
$Pos++;
}
我尝试过不使用while循环,它只打印一条记录,每个值都作为新行。我还尝试过只打印没有foreach语句的行,它只显示了单词Array 123次,但仍然跳过了第一行。我还尝试将while循环中的行变量从row更改为row1,两个结果都给出了相同的第一个缺失结果。
在比较mysql页面和mysqli页面的输出时,我还验证了第一行是否缺失。
获取表标题的第一行
您可以在while循环之前重置结果集的内部指针:
$RecordSet->data_seek(0);
while($row1 = $RecordSet->fetch_assoc())
$row = mysqli_fetch_assoc($RecordSet);
这是获取第一条记录,所以while循环的fetchasso((无法获取它。
您可能想要切换到一个do while循环。