亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Message board pagination developed in PHP

When a page displays a lot of data, we have to use our paging to display the data in pages. The paging code is as follows

<?php
session_start();
header("content-type:text/html;charset=utf-8");
$page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收頁碼
$page=!empty($page) ? $page :1;
$conn=mysqli_connect("localhost","root","root","Ressage");
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集
$table_name="ressage_user";//查取表名設(shè)置
$perpage=5;//每頁顯示的數(shù)據(jù)個(gè)數(shù)
//最大頁數(shù)和總記錄數(shù)
$total_sql="select count(*) from $table_name";
$total_result =mysqli_query($conn,$total_sql);
$total_row=mysqli_fetch_row($total_result);
$total = $total_row[0];//獲取最大頁碼數(shù)
$total_page = ceil($total/$perpage);//向上整數(shù)
//臨界點(diǎn)
$page=$page>$total_page ? $total_page:$page;//當(dāng)下一頁數(shù)大于最大頁數(shù)時(shí)的情況
//分頁設(shè)置初始化
$start=($page-1)*$perpage;

The paging code is divided into It is divided into two parts, one is to query data on the PHP page, and the other is to display the queried data on the HTML page. The html code is as follows

<div id="baner" style="margin-top: 20px">
    <a href="<?php
    echo "$_SERVER[PHP_SELF]?page=1"
    ?>">首頁</a>
    &nbsp;&nbsp;<a href="<?php
    echo "$_SERVER[PHP_SELF]?page=".($page-1)
    ?>">上一頁</a>
    <!--        顯示123456等頁碼按鈕-->
    <?php
    for($i=1;$i<=$total_page;$i++){
        if($i==$page){//當(dāng)前頁為顯示頁時(shí)加背景顏色
            echo "<a  style='padding: 5px 5px;background: #000;color: #FFF' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
        }else{
            echo "<a  style='padding: 5px 5px' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
        }
    }
    ?>
    &nbsp;&nbsp;<a href="<?php
    echo "$_SERVER[PHP_SELF]?page=".($page+1)
    ?>">下一頁</a>
    &nbsp;&nbsp;<a href="<?php
    echo "$_SERVER[PHP_SELF]?page={$total_page}"
    ?>">末頁</a>
    &nbsp;&nbsp;<span>共<?php echo $total?>條</span>
</div>

You only need to slightly change the above PHP code and change the database and data table. Add the local information and put the html code where you want it to be displayed on the page to achieve paging




##

Continuing Learning
||
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文網(wǎng)</title> </head> <body> <h2>PHP分頁代碼</h2> </body> </html>
submitReset Code