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

Display of the first and last pages of paging developed by PHP+Mysql

<html>
<head>
    <meta http-equiv="CONTENT-TYPE" content="text/html;">
</head>
<body>
<?php
/** 1.傳入頁面 **/
$page = $_GET['p'];
/** 2.根據(jù)頁面取出數(shù)據(jù):php->mysql **/
$host = "localhost";
$username = 'root';
$password = '123456789';
$db = 'bbs2';
$PageSize=5;
//連接數(shù)據(jù)庫
$conn = mysql_connect($host, $username, $password);
if(!$conn){
    echo "數(shù)據(jù)庫連接失敗";
    exit;
}
//選擇所要操作的數(shù)據(jù)庫
mysql_select_db($db);
//設(shè)置數(shù)據(jù)庫編碼格式
mysql_query('SET NAMES UTF8');
//編寫sql獲取分頁數(shù)據(jù):SELECT * FROM 表名 LIMIT 起始位置 , 顯示條數(shù)
$sql = "SELECT*FROM test LIMIT ".($page-1)*$PageSize .",$PageSize";
if(!$sql){
    echo "取出不成功";
};
//把sql語句傳送到數(shù)據(jù)庫
$result = mysql_query($sql);
//處理我們的數(shù)據(jù)
echo "<table border=1 cellspacing=0 width=15% >";
echo "<tr><td>ID</td><td>名字</td><td>性別</td></tr>";
while($row = mysql_fetch_assoc($result)){
    echo "<tr>";
    echo "<td>{$row['id']}</td>";
    echo "<td>{$row['name']}</td>";
    echo "<td>{$row['sex']}</td>";
    echo "<tr>";
}
//釋放結(jié)果
mysql_free_result($result);
//獲取數(shù)據(jù)總數(shù)
$to_sql="SELECT COUNT(*)FROM test";
$to_result=mysql_fetch_array(mysql_query($to_sql));
$to=$to_result[0];
//計(jì)算頁數(shù)
$to_pages=ceil($to/$PageSize);
mysql_close($conn);
/** 3.顯示數(shù)據(jù)+分頁條 **/
$page_banner="";
//計(jì)算偏移量
if($page>1){
    $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=1'>首頁</a>";
    $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一頁</a>";
}
if ($page<$to_pages){
    $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一頁</a>";
    $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($to_pages)."'>尾頁</a>";
}
$page_banner.="共{$to_pages}頁";
echo $page_banner;
?>
</body>
</html>

QQ截圖20161026152622.png

By adding the first and last pages, it makes it easier to jump to the paging bar

Code explanation:

if($page>1){
     $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=1'>首頁</a>";
     $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一頁</a>";
 }

Displayed when $page>1 Home page and previous page

if ($page<$to_pages){
     $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一頁</a>";
     $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($to_pages)."'>尾頁</a>";
 }

When the number of pages is less than the total number of pages, display the next and last page

$page_banner.="共{$to_pages}頁";
 echo $page_banner;

Output the total number of pages.


Continuing Learning
||
<html> <head> <meta http-equiv="CONTENT-TYPE" content="text/html;"> </head> <body> <?php /** 1.傳入頁面 **/ $page = $_GET['p']; /** 2.根據(jù)頁面取出數(shù)據(jù):php->mysql **/ $host = "localhost"; $username = 'root'; $password = '123456789'; $db = 'bbs2'; $PageSize=5; //連接數(shù)據(jù)庫 $conn = mysql_connect($host, $username, $password); if(!$conn){ // echo "數(shù)據(jù)庫連接失敗"; exit; } //選擇所要操作的數(shù)據(jù)庫 mysql_select_db($db); //設(shè)置數(shù)據(jù)庫編碼格式 mysql_query('SET NAMES UTF8'); //編寫sql獲取分頁數(shù)據(jù):SELECT * FROM 表名 LIMIT 起始位置 , 顯示條數(shù) $sql = "SELECT*FROM test LIMIT ".($page-1)*$PageSize .",$PageSize"; if(!$sql){ echo "取出不成功"; }; //把sql語句傳送到數(shù)據(jù)庫 $result = mysql_query($sql); //處理我們的數(shù)據(jù) echo "<table border=1 cellspacing=0 width=15% >"; echo "<tr><td>ID</td><td>名字</td><td>性別</td></tr>"; while($row = mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td>{$row['id']}</td>"; echo "<td>{$row['name']}</td>"; echo "<td>{$row['sex']}</td>"; echo "<tr>"; } //釋放結(jié)果 mysql_free_result($result); //獲取數(shù)據(jù)總數(shù) $to_sql="SELECT COUNT(*)FROM test"; $to_result=mysql_fetch_array(mysql_query($to_sql)); $to=$to_result[0]; //計(jì)算頁數(shù) $to_pages=ceil($to/$PageSize); mysql_close($conn); /** 3.顯示數(shù)據(jù)+分頁條 **/ $page_banner=""; //計(jì)算偏移量 if($page>1){ $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=1'>首頁</a>"; $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一頁</a>"; } if ($page<$to_pages){ $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一頁</a>"; $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($to_pages)."'>尾頁</a>"; } $page_banner.="共{$to_pages}頁"; echo $page_banner; ?> </body> </html>
submitReset Code