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

PHP? ??? ???? ???? ???? ??? ??? ?? ??

??? ??? ?? ?? ???? ???? ???? ?? ???? ???? ? ??????? ?? ????? ???? ??? ? ?????.

?? ??? ??? ??????? ?? ??? ???? ?? ????? ???? ??? ?? ?????. ???? ? ?? ?? ????? ?????.

? ???? ???? ?? ?: $limitNews

?? ??? ? ????: $page

??? ??? ????? 0?? ???? ???? ?????

???? ?? ?? 3?? ???? $limitNews = 3,

? ?? ??? $page = 1? 0, 1, 2 ? ?? ???? ?????

? ?? ??? $page = 2? ? ?? ??? 3, 4, 5? ?????

? ?? ??? $page = 3? ? ?? ??? 6, 7, 8

? ?????. ?. . . . . . . . .

$limitFrom ????? ???? ?? ??? ???? ??? ??????

?? ???? ?? ?? ? ????.

$limitFrom = ($page - 1) * $limitNews;

? 0, 3, 6? ???? ??? ????? ?????.


?? ??? ??????? ???? ???? ?? ????.

??? ??? ?? ?????? ?? test? ??? ??? ?? ?????.

<?php
$link = mysqli_connect('localhost','uesrname','password','test');

$sql = "select * from new";  //  select * from表示獲取全部字段的值

$sqlCount = "select count(*) from new";    //count(*)統(tǒng)計的是結果集的總條數(shù)
?>


???????? ?? ??? ?????. ?? ?? ?? ??? ??Quantity $countNews

<?php
$retQuery = mysqli_query($link, $sqlCount);  //查詢數(shù)量sql語句

$retCount = mysqli_fetch_array($retQuery);   //獲取數(shù)量

$count = $retCount[0]?$retCount[0]:0;   //判斷獲取的新聞數(shù)量

$countNews = $count;
?>


??? ?? ????? ???? ???$countPage ? ? ???? ?????

?? 10?? ?? ???? ?? ? ???? ??? ? ?? ??? ?????. 3?? ???? ???? ??? ???? ??? ?? ????

??? ??? ??? %? ???? ???.

<?php
$countPage = $countNews%$limitNews;   //求余數(shù)獲取分頁數(shù)量能否被除盡

if(($countPage) > 0) {  //獲取的頁數(shù)有余
  $countPage = ceil($countNews/$limitNews);  
  
// ceil() 函數(shù)向上舍入為最接近的整數(shù),除不盡則取整數(shù)+1頁, 10個新聞每個頁面顯示3個,成3個頁面,剩余1個單獨成1個頁面,這樣總共有4個頁面
} else {
  $countPage = $countNews/$limitNews;  //如果是9個新聞每個頁面顯示3個,成3個頁面
}
?>


?? ?????? ??? $prev, ?? ??? $next;

??? ???? "?? ???"? ???? ??? ?? ????. " "? ???? "?? ???"? ???? ?????

?? PHP ?? ??? ???? ????? ?? ???? ?????.

?? ??? $prev, ?? ??? $page -1 ???? ?? ???? ?????. ??, ?? ??? $page? ? ?? ???? ?? 0???? ?????. ?? ?? ??? ??? ?????.

??? ?? ??? $page? ? ?? ???? ?? ??? ???? ???. ????? "??"? ?????. "? ???"? ? ?? ???? ????? ???? ??? ???? ????.

$prev = ($page - 1 <= 0 )?1:$page-1;

?? ??? $next, ?? ??? $page -1, ?? ??? ??? ?? ???? ?? $page? ??? ???? ? "Next Page"? ???? ?? ?????.

?? ???? ???? ??? ???? ????? ??????.

$next = ($page + 1 > $countPage)?$countPage:$page+1;

//?? ??? ??? ?? ??? ??? ? ?? ?? ???? ?????. .

??? ??? ??? ????:

<!DOCTYPE html>
<html>
<head>  
<meta charset=utf8">  
<title>分表頁</title>
</head>
<body>
   <div>
         <a href="?page=<?php echo $prev;?>">|上一頁</a>         
         <?php for($i=1; $i<=$countPage; $i++):?>         
         <a href="?page=<?php echo $i;?>"><?php echo $i;?></a>         
         <?php endfor;?>         
         <a href="?page=<?php echo $next;?>">|下一頁</a>
   </div>
</body>
</html>

??: ? ??? for ??? ???? 1,2,3? ?????. . . . ??? ??.

???? ??
||
<?php $link = mysqli_connect('localhost','usermane','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } $page = isset($_GET['page'])?$_GET['page']:1;//獲取當前分頁數(shù) $limitNews = 3; //每頁顯示新聞數(shù)量 $countNews = 0; //總共有多少條新聞 $countPage = 0; //一共有多少頁數(shù) $limitFrom = ($page - 1) * $limitNews;//從第幾條數(shù)據(jù)開始讀記錄 //每頁顯示3個 //page = l limit 0 //page = 2 limit 3 //page = 3 limit 6 $sql = "select * from new"; $sqlCount = "select count(*) from new"; $retQuery = mysqli_query($link, $sqlCount); //查詢數(shù)量sql語句 $retCount = mysqli_fetch_array($retQuery); //獲取數(shù)量 $count = $retCount[0]?$retCount[0]:0; //判斷獲取的新聞數(shù)量 $countNews = $count; $countPage = $countNews%$limitNews; //求余數(shù)獲取分頁數(shù)量能否被除盡 if(($countPage) > 0) { //獲取的頁數(shù)有余 $countPage = ceil($countNews/$limitNews); // ceil() 函數(shù)向上舍入為最接近的整數(shù),除不盡則取整數(shù)+1頁, 10個新聞每個頁面顯示3個,成3個頁面,剩余1個成1個頁面 } else { $countPage = $countNews/$limitNews; } $prev = ($page - 1 <= 0 )?1:$page-1; //上一頁 $next = ($page + 1 > $countPage)?$countPage:$page+1; //下一頁 $result = mysqli_query($link, $sql); ?> <!DOCTYPE html> <html> <head> <meta charset=utf8"> <title>分頁</title> </head> <body> <div> <a href="?page=<?php echo $prev;?>">|上一頁</a> <?php for($i=1; $i<=$countPage; $i++):?> <a href="?page=<?php echo $i;?>"><?php echo $i;?></a> <?php endfor;?> <a href="?page=<?php echo $next;?>">|下一頁</a> </div> </body> </html>