高分求PHP~~翻页代码~~要求每页显示5-10条数据库中的数据~~越简单越好
答案:1 悬赏:0 手机版
解决时间 2021-02-27 14:13
- 提问者网友:黑米和小志
- 2021-02-27 02:11
高分求PHP~~翻页代码~~要求每页显示5-10条数据库中的数据~~越简单越好
最佳答案
- 五星知识达人网友:蓝房子
- 2021-02-27 02:53
一、分页类的内容
function totalNum($sql_t)
{
$res_totalNum = mysql_query($sql_t);
if($row_totalNum = mysql_fetch_row($res_totalNum))
{
$totalNum = $row_totalNum[0];
return $totalNum;
}
}
function curPage()
{
if(isset($_REQUEST["curpage"]))
{
$curPage = $_REQUEST["curpage"];
}
else
{
$curPage = 1;
}
return $curPage;
}
function page($pageSize,$sql_t)
{
$totalNum = totalNum($sql_t); //总页数
if($totalNum%$pageSize == 0)
{
$pageNum = $totalNum/$pageSize;
}
else
{
$pageNum = (int)($totalNum/$pageSize) + 1;
}
return $pageNum;
}
function record($curPage,$pageSize,$sql_g)
{
$sql_getRecord = $sql_g." limit ".($curPage-1)*$pageSize.",".$pageSize."";
$res_getRecord= mysql_query($sql_getRecord);
return $res_getRecord;
}
function pageDiv($pageSize,$sql_t,$pageName)
{
$curPage = curPage();
$pageNum = page($pageSize,$sql_t); //获得总分页数
if($curPage != 1)
{
$p1 = $curPage - 1;
echo "上一页";
echo " ";
echo "".$p1."";
echo " ";
}
else
{
echo "当前是第一页";
echo " ";
}
echo "".$curPage."";
if($curPage != $pageNum && $pageNum >0)
{
$p2 = $curPage + 1;
echo " ";
echo "".$p2."";
echo " ";
echo "下一页";
}
else
{
echo " ";
echo "当前是最后一页";
}
}
?>
二、调用的页面
无标题文档
include "getdb.php";
$d3b = new DB;
$d3b->init($host,$user,$pwd,$db);
$d3b->selDB();
include "divpage.php";
$curPage = curPage();
$res_getRecord = record($curPage,5,"select * from user");
while($row_getRecord = mysql_fetch_row($res_getRecord))
{
echo $row_getRecord[1]."
";
}
pageDiv(5,"select count(*) from user","test.php?");
?>
function totalNum($sql_t)
{
$res_totalNum = mysql_query($sql_t);
if($row_totalNum = mysql_fetch_row($res_totalNum))
{
$totalNum = $row_totalNum[0];
return $totalNum;
}
}
function curPage()
{
if(isset($_REQUEST["curpage"]))
{
$curPage = $_REQUEST["curpage"];
}
else
{
$curPage = 1;
}
return $curPage;
}
function page($pageSize,$sql_t)
{
$totalNum = totalNum($sql_t); //总页数
if($totalNum%$pageSize == 0)
{
$pageNum = $totalNum/$pageSize;
}
else
{
$pageNum = (int)($totalNum/$pageSize) + 1;
}
return $pageNum;
}
function record($curPage,$pageSize,$sql_g)
{
$sql_getRecord = $sql_g." limit ".($curPage-1)*$pageSize.",".$pageSize."";
$res_getRecord= mysql_query($sql_getRecord);
return $res_getRecord;
}
function pageDiv($pageSize,$sql_t,$pageName)
{
$curPage = curPage();
$pageNum = page($pageSize,$sql_t); //获得总分页数
if($curPage != 1)
{
$p1 = $curPage - 1;
echo "上一页";
echo " ";
echo "".$p1."";
echo " ";
}
else
{
echo "当前是第一页";
echo " ";
}
echo "".$curPage."";
if($curPage != $pageNum && $pageNum >0)
{
$p2 = $curPage + 1;
echo " ";
echo "".$p2."";
echo " ";
echo "下一页";
}
else
{
echo " ";
echo "当前是最后一页";
}
}
?>
二、调用的页面
include "getdb.php";
$d3b = new DB;
$d3b->init($host,$user,$pwd,$db);
$d3b->selDB();
include "divpage.php";
$curPage = curPage();
$res_getRecord = record($curPage,5,"select * from user");
while($row_getRecord = mysql_fetch_row($res_getRecord))
{
echo $row_getRecord[1]."
";
}
pageDiv(5,"select count(*) from user","test.php?");
?>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯