您的位置:首页 > 其它

今天早上起来写了一个smarty与函数相互结合的一个分页,上网搜了下发现他们写的太复杂,看不懂,自己写吧!写的不好,大家不要笑

2009-05-20 08:15 781 查看
一下是函数部分:

函数的页名称为:function_inc.php

函数的内容如下:

<?php

require_once("conn_inc.php");
require_once("smarty_inc.php");
function fenye ($num,$pagecontent=3){

global $offect,$pagecontent,$page,$num,$fist,$next,$pre,$list;
$url=$_SERVER['REQUEST_URI'];
$url=parse_url($url);
$url=$url[path];

$page=isset($_GET['page'])?intval($_GET['page']):1;
$contentpage=ceil($num/$pagecontent); //一共有多少页
if ($page>=$contentpage) {
$page=$contentpage;
}
if ($page<=0) {
$page=1;
}
$offect=($page-1)*$pagecontent; //计算偏移量
$fist=1; //第一页
$next=$page+1; //下一页
$pre= $page-1; //上一页
$list=$contentpage; //最后一页
/*
"一共 $page || $num 页 "; "<a href='$url?page=$fist' >第一页</a> "; "<a href='$url?page=$next' >下一页</a> ";
"<a href='$url?page=$pre' >上一页</a> "; "<a href='$url?page=$list' >最后一页</a>";
*/
}

?>

php程序页面如下:

程序页面的命名为:

login_list1.php

具体程序如下:

<?php
include_once("function_inc.php");
?>
<?php
$query1=mysql_query("select id from login ");
$num=mysql_num_rows($query1);
fenye($num,$pagecontent=1); //函数传值
?>
<?php
$query=mysql_query("select * from login order by id desc limit $offect,$pagecontent ");
while ($row=mysql_fetch_array($query)){
$array[]=array("id"=>$row[id],"name"=>"$row[name]","pass"=>"$row[pass]");
}
$smarty->assign("array",$array);
$smarty->assign("page",$page);
$smarty->assign("num",$num);
$smarty->assign("fist",$fist);
$smarty->assign("next",$next);
$smarty->assign("pre",$pre);
$smarty->assign("list",$list);
$smarty->display("login_list1.tpl.html");
?>

模板内容如下:

模板的文件命名为:login_list1.tpl.html

{include file="top.tpl.html"}
<table border="1" width="70%">
<tr>
<td>会员ID</td>
<td>用户名</td>
<td>密码</td>
</tr>
{section name=list loop=$array}
<tr>
<td>{$array[list].id}</td>
<td>{$array[list].name}</td>
<td>{$array[list].pass}</td>
</tr>
{/section}
</table>
一共 {$page}--{$num} 页  <a href="?page=1">第一页</a>  
<a href="?page={$next}">下一页</a>  <a href="?page={$pre}">上一页</a>  
<a href="?page={$list}">最后一页</a>
{include file="xia.tpl.html"}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐