- <?php
- header('Content-type:text/html; charset=utf-8');
- $link = mysql_connect('localhost', 'root', '36936999');
- mysql_select_db('test', $link);
- function fetch($sql, &$link){
- $query = mysql_query($sql, $link);
- return mysql_fetch_array($query);
- }
- function fetchs($sql, &$link){
- $query = mysql_query($sql, $link);
- while($row = mysql_fetch_array($query, MYSQL_ASSOC)){
- $record[] = $row;
- }
- return $record;
- }
- //==========================================================================================================//
- $stime = microtime(true);
- //==========================================================================================================//
- $table = 'sign';
- $pageSize = 80;
- $pageOffset = 100;
- $page = (int)$_GET['page'];
- $page = $page ? $page -1 : 0;
- $row = fetch("SELECT COUNT(id) AS total FROM {$table}", $link);
- $total = $row['total'];
- $count = ceil($total/$pageSize);
- echo '当前是页数:'.($page+1).'<br />';
- echo '当前表格的数据总量为:'.$total.'<br />';
- echo '设定的每页的记录数(步长)为:'.$pageSize.'<br />';
- echo '那么则会有分页数量:'.$count.'<br />';
- echo '设定的分页步长为:'.$pageOffset.'<br />';
- //===========================================================================================================//
- $start = $page * $pageSize;
- $end = $start + $pageSize -1;
- $sql = "SELECT id,uid,time,num,letter FROM sign WHERE id BETWEEN $start AND $end";
- echo $sql.'<br />';
- $result = fetchs($sql, $link);
- echo '<div style="width:600px; height:200px; margin-top:30px; word-break:break-all; word-wrap:break-word;">';
- foreach($result as $val){
- echo '<span>'.$val['id'].',</span>';
- }
- echo '</div>';
- $page ++;
- echo '<div style="width:600px; height:200px; margin-top:30px; word-break:break-all; word-wrap:break-word;">';
- if($page >= 1 && $page < $count){
- for($i=1; $i<$pageOffset; $i++){
- echo '<a style="margin:3px;" href="page.php?page='.($page+$i).'">'.($page+$i).'</a>';
- }
- }
- echo '</div>';
- //===========================================================================================================//
- $etime = microtime(true);
- echo $stime.'<br>';
- echo $etime.'<br>';
- echo '页面花费时间为:'.round($etime - $stime, 3);
- //该片段来自于http://www.codesnippet.cn/detail/1811201410986.html
来源: http://www.codesnippet.cn/detail/1811201410986.html