开发者

Setting the limit on the while function

开发者 https://www.devze.com 2023-02-18 16:21 出处:网络
Kindly let 开发者_运维技巧me know how can I put the limit on the record in the below function.I want to fetch all the record but one first page I want to show 5 only. Like pagination.

Kindly let 开发者_运维技巧me know how can I put the limit on the record in the below function. I want to fetch all the record but one first page I want to show 5 only. Like pagination.

while (($row = mysqli_fetch_array($rd)) ){

}


$times = 5;

while (($row = mysqli_fetch_array($rd)) && $times-- > 0){

}

However, this is not recommended! Use a limit clause in the SQL query instead, to avoid using a lot of CPU power for getting records you're not going to use anyway.


$limit  = 0;
while (($row = mysqli_fetch_array($rd)) && $limit < 5){
$limit++;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消