我用它来从数据库中获取结果。
$from=$to; ////limit from
$to=$from+5; ////limit to
$search_query="SELECT * FROM `user_info_secondary` WHERE `city`='$query' LIMIT $from,$to"
当我设置$to=0;
时,搜索会产生5个结果,但当我设置为$to=5,10,15....
时,它会显示6个结果,为什么会这样?
$from=$to;
$to=$from+5;
$search_query="SELECT * FROM `user_info_secondary` WHERE `city`='$query' LIMIT $from,$to";
$do_search= mysqli_query($connection, $search_query);
$number_of_results= mysqli_num_rows($do_search);
while($number_of_results>0)
{
$get_result_details= mysqli_fetch_array($do_search);
$search_result_details= $get_result_details['username'];
echo $search_result_details;
--$number_of_results;
}
答案 0 :(得分:0)
巴马尔说,它不是from
,to
- offset
,count
offset
中的5表示项目#4是它开始的地方
[0, 1, 2, 3, 4]
10个中的和count
导致:
0, 1, 2, 3 [START HERE] -> 4, 5, 6, 7, 8, 9 //(because 0 is part of that count so 9 is last).
又名 6项
offset
0表示从第0项开始,count
的结果为5
[START HERE] -> 0, 1, 2, 3, 4
又名 5项
$from = ##; // Where ## is the number you choose
$to = ($from > 0) ? $from + 4 : $from + 5;