php简单的分页程序
下面我们来看看我自己写的一个简单的php分页代码哦,其实在php中分页比较在asp中分页容易的多,这也可能是因为mysql有强大的功能的吧,这样节省不少系统资源了
<?php
function newlista($action) {
$sql = "Select * from gx_news ";
if ($action == 'today') {
$sql.= " where datediff(new_time," . date("Y-m-d") . ")<=0";
}
$result = mysql_query($sql) or die('fail1' . mysql_error());
$rs = mysql_fetch_array($result);
$rdcount = mysql_num_rows($result);
if ($rdcount) {
$pagesize = 15;
$pagecount = ($rdcount % $pagesize) ? (int)($rdcount / $pagesize) + 1 : $rdcount / $pagesize; //统计总页面
$page = isset($_GET['page']) ? $_GET['page'] : 1; //取得当前页面
$start = ($page >= 1 && $page <= $pagecount) ? $start = $pagesize * ($page - 1) : $start = 1; //取得超始记录
$start = $start;
$sql = $sql . " order by id desc limit $start,$pagesize";
$bg = 1;
//$resulte =mysql_query($sql) or die('fail'.mysql_error());
$result = mysql_query($sql) or die(mysql_error());
while ($rs = mysql_fetch_array($result)) {
if ($bg % 2 != 0) {
$style = "class=color";
} else {
$style = "";
}
echo "<li $style><a href='newscenter.php?id=".$rs[0]."' target=_blank >".$rs['new_title']."</a><span>[".$rs['new_time']."]</span></li>";
$bg++;
}
echo '</ul><div class=navigation>';
echo "" . pagelist($page, $pagecount, $rdcount, '?page=', $pagesize) . "</div>";
} else {
echo '暂时没有信息!';
}
}本文地址:http://www.phprm.com/code/7202541d5fed8844999729fd8d178f6a.html
转载随意,但请附上文章地址:-)