Php 如何在分页中显示长时间/for循环?
我有一个有数千个结果的while/for循环。因为它包含几个字段,所以我使用table来显示它。但是,由于同时显示数千个结果,这肯定会降低性能。如何在分页中显示它Php 如何在分页中显示长时间/for循环?,php,Php,我有一个有数千个结果的while/for循环。因为它包含几个字段,所以我使用table来显示它。但是,由于同时显示数千个结果,这肯定会降低性能。如何在分页中显示它 <table> <?php $count = 1000; for($a=1;$a<=$count;$a++) { ?> <tr> <td><?php echo $a; ?></td>
<table>
<?php $count = 1000;
for($a=1;$a<=$count;$a++) { ?>
<tr>
<td><?php echo $a; ?></td>
<td>This is number <?php echo $a; ?></td>
</tr>
<?php $i++;
} ?>
</table>
这是电话号码
如果数据来自数据库,则可以限制结果集。如果您使用的是MySQL,则使用LIMIT
子句。这将允许您仅获取指定数量的行
SELECT title, description FROM posts LIMIT 25
这将只获取25行。然后,如果要在第25行之后获取结果,可以提供偏移量。由于在LIMIT子句中偏移量是第一位的,所以这样做有点不同。只提供了一个参数,MySQL假定其为限制。选择接下来使用的50行
SELECT title, description FROM posts LIMIT 25, 50
由于需要处理的数据量较小,这有助于减少获取的结果集,并有助于提高性能/加载时间
我希望这能帮助你,快乐编码
更新
在MySQL中使用LIMIT子句时,如果数据来自数据库,则可以限制结果集。如果您使用的是MySQL,则使用
LIMIT
子句。这将允许您仅获取指定数量的行
SELECT title, description FROM posts LIMIT 25
这将只获取25行。然后,如果要在第25行之后获取结果,可以提供偏移量。由于在LIMIT子句中偏移量是第一位的,所以这样做有点不同。只提供了一个参数,MySQL假定其为限制。选择接下来使用的50行
SELECT title, description FROM posts LIMIT 25, 50
由于需要处理的数据量较小,这有助于减少获取的结果集,并有助于提高性能/加载时间
我希望这能帮助你,快乐编码
更新
在MySQL中使用LIMIT子句时,如果数据来自数据库,则可以限制结果集。如果您使用的是MySQL,则使用
LIMIT
子句。这将允许您仅获取指定数量的行
SELECT title, description FROM posts LIMIT 25
这将只获取25行。然后,如果要在第25行之后获取结果,可以提供偏移量。由于在LIMIT子句中偏移量是第一位的,所以这样做有点不同。只提供了一个参数,MySQL假定其为限制。选择接下来使用的50行
SELECT title, description FROM posts LIMIT 25, 50
由于需要处理的数据量较小,这有助于减少获取的结果集,并有助于提高性能/加载时间
我希望这能帮助你,快乐编码
更新
在MySQL中使用LIMIT子句时,如果数据来自数据库,则可以限制结果集。如果您使用的是MySQL,则使用
LIMIT
子句。这将允许您仅获取指定数量的行
SELECT title, description FROM posts LIMIT 25
这将只获取25行。然后,如果要在第25行之后获取结果,可以提供偏移量。由于在LIMIT子句中偏移量是第一位的,所以这样做有点不同。只提供了一个参数,MySQL假定其为限制。选择接下来使用的50行
SELECT title, description FROM posts LIMIT 25, 50
由于需要处理的数据量较小,这有助于减少获取的结果集,并有助于提高性能/加载时间
我希望这能帮助你,快乐编码
更新
在MySQL中使用LIMIT子句时,我唯一没有数据库的解决方案是将当前的数组键传递到下一页。例如:
$start = 1;
$end = 1000;
if(isset($_GET['record_number'])){
$start = $_GET['record_number'];
$end = $_GET['record_number'] + 1000;
}
for($a=$start; $a<=$end; $a++){
//code here
}
$start=1;
$end=1000;
如果(isset($\u GET['record\u number'])){
$start=$\u GET['record\u number'];
$end=$\u GET['record\u number']+1000;
}
对于($a=$start;$a我唯一没有数据库的解决方案是将当前的数组键传递到下一页。例如:
$start = 1;
$end = 1000;
if(isset($_GET['record_number'])){
$start = $_GET['record_number'];
$end = $_GET['record_number'] + 1000;
}
for($a=$start; $a<=$end; $a++){
//code here
}
$start=1;
$end=1000;
如果(isset($\u GET['record\u number'])){
$start=$\u GET['record\u number'];
$end=$\u GET['record\u number']+1000;
}
对于($a=$start;$a我唯一没有数据库的解决方案是将当前的数组键传递到下一页。例如:
$start = 1;
$end = 1000;
if(isset($_GET['record_number'])){
$start = $_GET['record_number'];
$end = $_GET['record_number'] + 1000;
}
for($a=$start; $a<=$end; $a++){
//code here
}
$start=1;
$end=1000;
如果(isset($\u GET['record\u number'])){
$start=$\u GET['record\u number'];
$end=$\u GET['record\u number']+1000;
}
对于($a=$start;$a我唯一没有数据库的解决方案是将当前的数组键传递到下一页。例如:
$start = 1;
$end = 1000;
if(isset($_GET['record_number'])){
$start = $_GET['record_number'];
$end = $_GET['record_number'] + 1000;
}
for($a=$start; $a<=$end; $a++){
//code here
}
$start=1;
$end=1000;
如果(isset($\u GET['record\u number'])){
$start=$\u GET['record\u number'];
$end=$\u GET['record\u number']+1000;
}
对于($a=$start;$a这里是我的例子,它与@AnotherGuy的答案类似
<form method="GET">
<input type="text" name="rowsPerPage">
<?php
for($i = 1; $i+1 < $count/$rowsPerPage; $i++){
echo '<input type="submit" name="page" value="'.$i.'">';
}
?>
</form>
<?php
$begin = (int)$_GET['rowsPerPage']*$_GET['page'];
$take = (int)$_GET['rowsPerPage'];
$sql = "SELECT ... LIMIT {$begin}, {$take}";
?>
代码可能包含“拼写错误”,但我希望它能给您带来新的想法
我建议您使用GET而不是POST。GET将保存在URL中,这样,在不丢失页面设置的情况下,可以更轻松地重新加载页面
www.example.com?rowsPerPage=150&page=2这是我的例子,它与@AnotherGuy的答案类似
<form method="GET">
<input type="text" name="rowsPerPage">
<?php
for($i = 1; $i+1 < $count/$rowsPerPage; $i++){
echo '<input type="submit" name="page" value="'.$i.'">';
}
?>
</form>
<?php
$begin = (int)$_GET['rowsPerPage']*$_GET['page'];
$take = (int)$_GET['rowsPerPage'];
$sql = "SELECT ... LIMIT {$begin}, {$take}";
?>
代码可能包含“拼写错误”,但我希望它能给您带来新的想法
我建议您使用GET而不是POST。GET将保存在URL中,这样,在不丢失页面设置的情况下,可以更轻松地重新加载页面
www.example.com?rowsPerPage=150&page=2这是我的例子,它与@AnotherGuy的答案类似
<form method="GET">
<input type="text" name="rowsPerPage">
<?php
for($i = 1; $i+1 < $count/$rowsPerPage; $i++){
echo '<input type="submit" name="page" value="'.$i.'">';
}
?>
</form>
<?php
$begin = (int)$_GET['rowsPerPage']*$_GET['page'];
$take = (int)$_GET['rowsPerPage'];
$sql = "SELECT ... LIMIT {$begin}, {$take}";
?>
代码可能包含“拼写错误”,但我希望它能给您带来新的想法
我建议您使用GET而不是POST。GET将保存在URL中,这样,在不丢失页面设置的情况下,可以更轻松地重新加载页面
www.example.com?rowsPerPage=150&page=2这是我的例子,它与@AnotherGuy的答案类似
<form method="GET">
<input type="text" name="rowsPerPage">
<?php
for($i = 1; $i+1 < $count/$rowsPerPage; $i++){
echo '<input type="submit" name="page" value="'.$i.'">';
}
?>
</form>
<?php
$begin = (int)$_GET['rowsPerPage']*$_GET['page'];
$take = (int)$_GET['rowsPerPage'];
$sql = "SELECT ... LIMIT {$begin}, {$take}";
?>
代码可能包含“拼写错误”,但我希望它能给您带来新的想法
我会记录