phpweb怎么加文章上一篇下一篇翻页 5
展开全部
设置一个翻页类:page.class.php:
<?php
function _PAGEFT($totle, $displaypg = 20, $url = '') {
global $page, $firstcount, $pagenav, $_SERVER;
$GLOBALS["displaypg"] = $displaypg;
if (!$page)
$page = 1;
if (!$url) {
$url = $_SERVER["REQUEST_URI"];
}
//URL分析:
$parse_url = parse_url($url);
$url_query = $parse_url["query"]; //单独取出URL的查询字串
if ($url_query) {
$url_query = preg_replace("/(^|&)page=$page/", "", $url_query);
$url = str_replace($parse_url["query"], $url_query, $url);
if ($url_query)
$url .= "&page";
else
$url .= "page";
} else {
$url .= "?page";
}
$lastpg = ceil($totle / $displaypg); //最后页,也是总页数
$page = min($lastpg, $page);
$prepg = $page -1; //上一页
$nextpg = ($page == $lastpg ? 0 : $page +1); //下一页
$firstcount = ($page -1) * $displaypg;
//开始分页导航条代码:
$pagenav = "显示第 <B>" . ($totle ? ($firstcount +1) : 0) . "</B>-<B>" . min($firstcount + $displaypg, $totle) . "</B> 条记录,共 $totle 条记录";
//如果只有一页则跳出函数:
if ($lastpg <= 1)
return false;
$pagenav .= " <a href='$url=1'>首页</a> ";
if ($prepg)
$pagenav .= " <a href='$url=$prepg'>前页</a> ";
else
$pagenav .= " 前页 ";
if ($nextpg)
$pagenav .= " <a href='$url=$nextpg'>后页</a> ";
else
$pagenav .= " 后页 ";
$pagenav .= " <a href='$url=$lastpg'>尾页</a> ";
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for ($i = 1; $i <= $lastpg; $i++) {
if ($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共 $lastpg 页";
}
?>
调用这个类,之后就可以实现翻页:
<?php
include ("admin_global.php");
$r=$db-> Get_user_shell_check($uid, $shell);
$page=$_GET[page];
$result=$db->query("SELECT * FROM `p_newsbase`");
$total=$db->num_rows($result);
_PAGEFT($total,5);
echo $pagenav;
$query=$db->query("SELECT * FROM `p_newsbase` limit $firstcount,$displaypg ");
while($row=$db->fetch_array($query)){
echo "<hr><b>".$row[id]." | ".$row[title];
}
?>
<?php
function _PAGEFT($totle, $displaypg = 20, $url = '') {
global $page, $firstcount, $pagenav, $_SERVER;
$GLOBALS["displaypg"] = $displaypg;
if (!$page)
$page = 1;
if (!$url) {
$url = $_SERVER["REQUEST_URI"];
}
//URL分析:
$parse_url = parse_url($url);
$url_query = $parse_url["query"]; //单独取出URL的查询字串
if ($url_query) {
$url_query = preg_replace("/(^|&)page=$page/", "", $url_query);
$url = str_replace($parse_url["query"], $url_query, $url);
if ($url_query)
$url .= "&page";
else
$url .= "page";
} else {
$url .= "?page";
}
$lastpg = ceil($totle / $displaypg); //最后页,也是总页数
$page = min($lastpg, $page);
$prepg = $page -1; //上一页
$nextpg = ($page == $lastpg ? 0 : $page +1); //下一页
$firstcount = ($page -1) * $displaypg;
//开始分页导航条代码:
$pagenav = "显示第 <B>" . ($totle ? ($firstcount +1) : 0) . "</B>-<B>" . min($firstcount + $displaypg, $totle) . "</B> 条记录,共 $totle 条记录";
//如果只有一页则跳出函数:
if ($lastpg <= 1)
return false;
$pagenav .= " <a href='$url=1'>首页</a> ";
if ($prepg)
$pagenav .= " <a href='$url=$prepg'>前页</a> ";
else
$pagenav .= " 前页 ";
if ($nextpg)
$pagenav .= " <a href='$url=$nextpg'>后页</a> ";
else
$pagenav .= " 后页 ";
$pagenav .= " <a href='$url=$lastpg'>尾页</a> ";
//下拉跳转列表,循环列出所有页码:
$pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n";
for ($i = 1; $i <= $lastpg; $i++) {
if ($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>\n";
else
$pagenav .= "<option value='$i'>$i</option>\n";
}
$pagenav .= "</select> 页,共 $lastpg 页";
}
?>
调用这个类,之后就可以实现翻页:
<?php
include ("admin_global.php");
$r=$db-> Get_user_shell_check($uid, $shell);
$page=$_GET[page];
$result=$db->query("SELECT * FROM `p_newsbase`");
$total=$db->num_rows($result);
_PAGEFT($total,5);
echo $pagenav;
$query=$db->query("SELECT * FROM `p_newsbase` limit $firstcount,$displaypg ");
while($row=$db->fetch_array($query)){
echo "<hr><b>".$row[id]." | ".$row[title];
}
?>
推荐于2016-06-25
展开全部
找到目录/news/module,该目录下存放的所有关于文文章的函数文件,一个文件就是一个函数,找到newsContent.php文件。在81行左右添加如下代码(注意位置的逻辑关系):
$fsql->query("select * from pwn_news_con where catid = '$catid' and id > '$id' order by id asc limit 1");
if($fsql->next_record())
{
$pre_info = "f('id').".html>".$fsql->f('title')."";
}
else
{
$pre_info = "没有了";
}
$fsql->query("select * from pwn_news_con where catid = '$catid' and id < '$id' order by id desc limit 1");
if($fsql->next_record())
{
$nex_info = "f('id').".html>".$fsql->f('title')."";
}
else
{
$nex_info = "没有了";
}
由于使用了模板技术,需要把$pre_info与$nex_info传递至模板文件,这步很重要:
在237行左右,在数组$var中添加元素
'nex_info' =>$nex_info,
'pre_info' =>$pre_info,
在目录/news/templates找到tpl_newscontent.htm
在想要添加的地方添加以下代码:
上一篇:{ #pre_info# } 下一篇:{ #nex_info# }
最后保存,上传。
$fsql->query("select * from pwn_news_con where catid = '$catid' and id > '$id' order by id asc limit 1");
if($fsql->next_record())
{
$pre_info = "f('id').".html>".$fsql->f('title')."";
}
else
{
$pre_info = "没有了";
}
$fsql->query("select * from pwn_news_con where catid = '$catid' and id < '$id' order by id desc limit 1");
if($fsql->next_record())
{
$nex_info = "f('id').".html>".$fsql->f('title')."";
}
else
{
$nex_info = "没有了";
}
由于使用了模板技术,需要把$pre_info与$nex_info传递至模板文件,这步很重要:
在237行左右,在数组$var中添加元素
'nex_info' =>$nex_info,
'pre_info' =>$pre_info,
在目录/news/templates找到tpl_newscontent.htm
在想要添加的地方添加以下代码:
上一篇:{ #pre_info# } 下一篇:{ #nex_info# }
最后保存,上传。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
PHPWEB后台排版增加插件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询