每次我使用此代码时,它都会消除一个结果。
假设我数据库中有 10 行,它只会显示 9 行
我知道这段代码不在PDO或MySQLi中,但这不是问题所在
mysql_select_db($database_localhost, $localhost);
$query_tutorunit = "SELECT * FROM tutorunit WHERE tutorID = $colname_unitg";
$tutorunit = mysql_query($query_tutorunit, $localhost) or die(mysql_error());
$row_tutorunit = mysql_fetch_assoc($tutorunit);
$totalRows_tutorunit = mysql_num_rows($tutorunit);
$confirmtwo = "";
while ($row_tutorunit = mysql_fetch_array($tutorunit)) {
$confirmtwo .= $row_tutorunit["code"];
}
echo $confirmtwo;
当我使用do时,它会显示所有结果。
<?php do { ?>
<p><?php echo $row_tutorunit["code"]; ?></p>
<?php } while ($row_tutorunit = mysql_fetch_assoc($tutorunit)); ?>
但我不想使用do-while。我哪里出错了?
删除该行:
$row_tutorunit = mysql_fetch_assoc($tutorunit);
mysql_fetch_assoc
和mysql_fetch_array
都移动指针。