当使用 PHP 和 MySql 选择显示数据时,如何获取记录集中最后一行的值? MySql 或 Php 中是否有内置函数来执行此操作?
例如(使用 PDO):
select id from table limit 5;
Output:
1
2
3
4
5 -> How can I get this value to pass to a function, all things being the same
while( $row = $stmt->fetch() ) {
echo $row['id'];
}
// The value of id of the last row i.e 5 needs to go into a function
functionName(id value of last row goes here)
如何做到这一点?
最佳答案
$last_id = 0
while( $row = $stmt->fetch() ) {
echo $row['id'];
$last_id = $row['id'];
}
functionName($last_id)
关于php - 使用 MySql 和 PHP 时获取记录集中最后一条记录的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19024895/