自己写的php分页函数,蛮好用的。代码如下: data.inc.php <?php /* * Created on 2009/4/30 by fanfan * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ class data { var $host; var $name; var $pass; var $database; function data() { $this->host = 'localhost'; $this->name = 'root'; $this->pass = 'admin'; $this->database = 'zq'; $this->connect(); } … /** * show the page footer * * @access public * @param integer $total * @param integer $pagesize * @param integer $pageid * @param string $str * @param string $link * @return string */ function show_page($total, $pagesize, $pageid = 1, $str = ' 文章 ', $link = '?') { $myecho = ''; $pagetotal = ceil($total / $pagesize); $myecho .= '<div class="page">'; $myecho .= '共有 '; $myecho .= $total; $myecho .= $str; $myecho .= $pageid . '/' . $pagetotal . ' 頁 '; if ($pageid <> 1) $myecho .= "<a href="$link&pageid=" . ($pageid -1) . "" mce_href="$link&pageid=" . ($pageid -1) . "">上一頁</a> "; if ($pageid <> $pagetotal) $myecho .= "<a href="$link&pageid=" . ($pageid +1) . "" mce_href="$link&pageid=" . ($pageid +1) . "">下一頁</a> "; $myecho .= '<select name="select" onchange="javascript:location.href=/'' . $link . '&pageid=/'+this.value;">'; for ($i = 1; $i <= $pagetotal; $i++) { $myecho .= "<option value='$i'"; if ($pageid == $i) $myecho .= " selected='selected'"; $myecho .= ">第" . $i . "頁</option>"; $myecho .= ''; } $myecho .= '</select>'; $myecho .= '</div>'; return $myecho; } … } ?> page_test.php <?php include_once ('class/data.inc.php'); $pagesize = 2; $pageid = isset($_GET['pageid'])?mysql_real_escape_string($_GET['pageid']):1; $mydata = new data(); $link = 'index.php?link=search'; //-----show page $str = "select * from article where cate_id = 4"; $res = $mydata->all_array($str); $total = count($res); echo $mydata->show_page($total, $pagesize, $pageid,' 條資訊 ',$link); //---------------------------------------------------// ?> 效果如下: