使用php和mysql时,如何检测结果集中的最后一条记录。在ASP中它的EOF(文件结束)。什么是php / mysql相当于什么?我想知道最后一条记录,所以我可以在它之后画一条线或者关闭标签或其他任何东西。
答案 0 :(得分:8)
您可以使用mysqli_num_rows查看结果集中有多少行,并让计数器知道您打印的行数。
$total_rows = mysqli_num_rows($resultset);
$counter = 0;
while($row = mysqli_fetch_assoc($resultset)) {
//do something with every row here
//last row?
if(++$counter == $total_rows) {
echo '<hr>';
}
}
或者您可以循环遍历行并在循环后打印您的行/标记/
while($row = mysqli_fetch_assoc($resultset)) {
//do something with every row
}
echo '<hr>';