??? ?? ?? ??
?? ???? ?? ??? ?? HTML ???? ??? ??????. ???? SQL ?? ?? ?????? ???? ???? ???? ???? ???. ????? ??? ??? ???? ?????. ?? ? ???? ???? ??? ???? ????.
?? ??? ??? ??????? ?? ??? ??? ???? ????? ??? ?? ?????. ???? ? ?? ?? ????? ?????.
???? ?? ?: $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? ???? ???? ???? ?????.
?? ?? ?? ?????? ???? ? ?? ?? ?????. $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? ? ?? ???? ?, ?? ??? $page? ? ?? ???? ?, "?? ???"? ???? ?????. ? ?? ???? ???? ? ?? ??? ???? ??? ?????.
<?php $prev = ($page - 1 <= 0 )?1:$page-1; ?>
?? ??? $next? ?? ??? $page -1?? ???? ?? ???? ?????. ??? $page? ??? ???? ? "?? ???"? ??? ?? ?? ????? ????. Follow ?? ???? ???? ??? ???? ????? ??????.
<?php $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>
???? ??????
?????? ? ?? ??? ???? ???? ??? ??? ???? ? ????.
while ?? ???? ??????? ???? ???? list.php ??? ?????. <?php while($rows=mysqli_fetch_array($result)):?>
<tr>
<td style="text-align:left; padding-left:20px;">
<input type="checkbox" name="id[]" value="<?php echo $rows["id"]?>" />
<?php echo $rows["id"]?></td>
<td><input type="text" name="sort[1]" value="1" style="width:50px; text-align:center; border:1px solid #ddd; padding:7px 0;" /></td>
<td width="10%">
<video width="200" height="150" controls="controls" >
<source src="<?php echo $rows["video"]?>" type="video/mp4">
</video>
</td>
<td><?php echo $rows["title"]?></td>
<td><font color="#00CC99">首頁</font></td>
<td><?php echo $rows["cate_name"]?></td>
<td><?php echo date("Y-m-d H:i:s",$rows["time"])?></td>
<td>
<div class="button-group">
<a class="button border-main" href="#"><span class="icon-edit"></span>修 改</a>
<a class="button border-red" href="#" onclick="return del(1,1,1)">
<span class="icon-trash-o"></span>刪 除
</a>
</div>
</td>
</tr>
<?php endwhile;?>
??: ????? ?? ??? ???? ?????? ???? ?? ?? ???? ?????.