在php中为数百个页面按钮分页(或者我需要使用javascript?)

在php中为数百个页面按钮分页(或者我需要使用javascript?),javascript,php,html,pagination,paging,Javascript,Php,Html,Pagination,Paging,我想问一下,如何像谷歌那样做简单的分页和分页 我应该使用javascript吗 我应该使用引导程序吗 这是我分页的代码,我现在有30个页面按钮,每页有9条记录 所有这些都出现在页面上 $results_per_page = 9; // find out the number of results stored in database $result = mysqli_query($link, $query); $number_of_results = mysqli_num_rows($resul

我想问一下,如何像谷歌那样做简单的分页和分页

我应该使用javascript吗

我应该使用引导程序吗

这是我分页的代码,我现在有30个页面按钮,每页有9条记录

所有这些都出现在页面上

$results_per_page = 9;
// find out the number of results stored in database
$result = mysqli_query($link, $query);
$number_of_results = mysqli_num_rows($result);
// determine number of total pages available
$number_of_pages = ceil($number_of_results/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page'])) {
    $page = 1;
} else {
    $page = $_GET['page'];
}

// determine the sql LIMIT starting number for the results on the displaying page

$this_page_first_result = ($page-1)*$results_per_page;
// retrieve selected results from database and display them on page
$sql='SELECT * FROM policy LIMIT ' . $this_page_first_result . ',' .  $results_per_page;

$result = mysqli_query($link, $sql);

// display the links to the pages
?>
<form method="post">
<?php
for ($page=1;$page<=$number_of_pages;$page++) {
?>
    <input class="btn btn-success" type="submit" value="<?php echo $page;?>" name="page" >
<?php  
}
?>

</form>

<?php
$page = 0;
?>
$results\u per\u page=9;
//找出数据库中存储的结果数
$result=mysqli\u查询($link,$query);
$number_of_results=mysqli_num_行($result);
//确定可用的总页数
$number_of_pages=ceil($number_of_results/$results_per_pages);
//确定访问者当前所在的页码
如果(!isset($\u GET['page'])){
$page=1;
}否则{
$page=$_GET['page'];
}
//确定显示页面上结果的sql限制起始编号
$this_page_first_result=($page-1)*$results_每页;
//从数据库检索所选结果并将其显示在第页上
$sql='SELECT*FROM policy LIMIT'$此页面为第一个结果。“,”$每页的结果;
$result=mysqli\u查询($link,$sql);
//显示指向页面的链接
?>

您可以限制当前页面左侧和右侧显示的页数。假设您在第33/100页,希望显示以下内容:

<First> ... 30 31 32 [33] 34 35 36 37 38 39 40 ... <Last>
。。。30 31 32 [33] 34 35 36 37 38 39 40 ... 
左边3页,右边7页

要实现这一点,请使用以下内容:

$pageDisplayToLeft = 3;
$pageDisplayToRight = 7;
$pagesTotal = 100;
$currentPage = 33;

echo '<First>';

if(($currentPage - $pageDisplayToLeft) > 1) {
    echo ' ... ';
}

$pageDisplay = max(1, $currentPage - $pageDisplayToLeft);
while($pageDisplay < $currentPage) {
    echo $pageDisplay . ' ';
    $pageDisplay++;
}
echo '[' . $currentPage . '] ';

$pageDisplay = min($pagesTotal, $currentPage + 1);
while($pageDisplay <= min($currentPage + $pageDisplayToRight, $pagesTotal)) {
    echo $pageDisplay . ' ';
    $pageDisplay++;
}


if(($currentPage + $pageDisplayToRight) < $pagesTotal) {
    echo ' ... ';
}

echo '<Last>';
$pageDisplayToLeft=3;
$pageDisplayToRight=7;
$pagesTotal=100;
$currentPage=33;
回声';
如果($currentPage-$pageDisplayToLeft)>1){
回声“…”;
}
$pageDisplay=max(1,$currentPage-$pageDisplayToLeft);
而($pageDisplay<$currentPage){
echo$pageDisplay。“;
$pageDisplay++;
}
回显“[”.$currentPage.]”;
$pageDisplay=min($pagesTotal,$currentPage+1);

尽管如此,请阅读。我们希望你在这里表现出更多的努力,而不仅仅是告诉我们你“想要什么”Bootstrap是一种演示工具,因此在页面中任何明显的方式对你的脚本攻击都是无济于事的。甚至你应该考虑使用<代码> MySqLi<<代码>或<代码> PDO < /Cord> API,而不是级联值。