创造世界上最简单的 PHP 开发模式第2/5页
更新时间:2006年12月04日 00:00:00 投稿:mdxy-dxy
这篇文章主要介绍了创造世界上最简单的 PHP 开发模式
七:文章列表察看页面实现和模板处理(万里长征的最后一步)
先来看看页面list1的实现,在list1里面分页用了一个page.js文件,这个文件是自己给自己写的一个js分页的函数,挺好用的
---------------page.js---------------
//--------共 20 条记录,当前 86/99 页 [1]... [82] [83] [84] [85] [86] [87] [88] [89] [90] ...[99] GO-------------------
//recordCount = 20;
//show = 20
//pageShow = 11;
//pageCount = 100;
//pageNow = 86;
//pageStr = "?page=_page_";
//document.write(showListPage(recordCount, show, pageCount, pageNow, pageStr));
function showListPage(recordCount, show, pageShow, pageCount, pageNow, pageStr){
if(pageCount<1) pageCount =0;
if(pageNow<1) pageNow = 0;
str = ’共 <B>’+recordCount+’</B> 条记录,当前 <B>’+pageNow+’/’+pageCount+’</B> 页 ’;
if(pageCount<=pageShow){
startHave = false;
endHave = false;
startNum = 1;
endNum = pageCount;
} else if(pageNow-1 <= pageShow/2){
startHave = false;
endHave = true;
startNum = 1;
endNum = pageShow-1;
} else if(pageCount-pageNow <= pageShow/2){
startHave = true;
endHave = false;
startNum = pageCount - pageShow + 2;
endNum = pageCount;
} else {
startHave = true;
endHave = true;
startNum = pageNow - Math.floor((pageShow-2)/2);
endNum = startNum + pageShow - 3;
}
if(startHave){
startStr = " [<A href=’"+pageStr.replace("_page_",1)+"’>1</A>]... ";
str += startStr;
}
for(i=startNum; i<=endNum; i++){
if(pageNow==i)
str += "[" + i + "]";
else
str += " [<A href=’" + pageStr.replace("_page_",i) + "’>" + i + "</A>] ";
}
if(endHave){
endStr = " ...[<A href=’" + pageStr.replace("_page_",pageCount) + "’>" + pageCount + "</A>] ";
str += endStr;
}
return str;
}
--------------list1.htm----------------
<a href="new.php">添加新文章</a><hr>
<table>
<tr><th>php开发文章</th></tr>
<!-- BEGIN phplist -->
<tr><td>{id}--<a href="view.php?id={id}">{title}</a></td></tr>
<!-- END phplist -->
</table>
<!-- BEGIN phplist_page -->
<script src="page.js" language="javascript"></script>
<script language="javascript">
recordCount = {recordCount}; //总记录数
show = {pageSize}; //每页显示的记录数量
pageShow = 10; //每页显示的分页连接数量
pageCount = {pageCount}; //总页数
pageNow = {page}; //当前页数
pageStr = "?page=_page_"; //页面连接
document.write(showListPage(recordCount, show, pageShow, pageCount, pageNow, pageStr));
</script>
<!-- END phplist_page -->
<hr>
<table ID="Table1">
<tr><th>php开发热点文章</th></tr>
<!-- BEGIN phphotlist -->
<tr><td>{id}--<a href="view.php?id={id}">{title}</a></td></tr>
<!-- END phphotlist -->
</table><hr>
<table ID="Table2">
<tr><th>asp开发最新文章</th></tr>
<!-- BEGIN aspnewlist -->
<tr><td>{id}--<a href="view.php?id={id}">{title}</a></td></tr>
<!-- END aspnewlist -->
</table>
--------------list1.php----------------
<?php
require_once "config.inc.php";
dbConnect();
$data = array();
$data[phplist] = getArticleList(1, "id DESC", (int)$_GET
相关文章
PHP – EasyUI DataGrid 资料存的方式介绍
继上篇文章 PHP – EasyUI DataGrid 资料取的方式,本篇一條小龍继续讲述,如何操作 DataGrid,把资料存入资料库,并实现 MVC 架构,将资料层分离、独立运作2012-11-11
最新评论