Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli限制产生的结果比限制多_Php_Mysql - Fatal编程技术网

Php mysqli限制产生的结果比限制多

Php mysqli限制产生的结果比限制多,php,mysql,Php,Mysql,我正在使用它从数据库中获取结果 $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_qu

我正在使用它从数据库中获取结果

$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;
} 
正如巴尔马所说,它不是从,到-它的偏移量,计数

偏移量为5意味着第4项是它的起点

[0, 1, 2, 3, 4] 
并在以下情况下计数10个结果:

0, 1, 2, 3 [START HERE] -> 4, 5, 6, 7, 8, 9 //(because 0 is part of that count so 9 is last). 
aka 6项

偏移量0表示从项目0开始,计数为5将导致

[START HERE] -> 0, 1, 2, 3, 4
aka 5项

只需执行以下操作即可修复它:
这不是从,到,这是偏移量,计数。对不起,这就是我的意思,我在这方面真的很新,不知道所有的术语,那么代码有什么问题吗?每当我看到使用mysqli_查询的人仍在传递未替换的变量,我死在一点里面。我真的很抱歉,我甚至不知道未替换的变量意味着什么,我真的很新。我会尝试阅读并改进我自己。当我几天前以同样的方式尝试时,它没有修复它。我想我自己明白抵消和计数的真正含义
$from = ##;  // Where ## is the number you choose
$to = ($from > 0) ? $from + 4 : $from + 5;