php分页函数
<?php
function page ( $totalPage , $currentPage,$url ,$halfPer=5)
{
$total=$totalPage-1;
$re="<td><a href="\" mce_href="\""$url\" onclick=\"page=prompt('共{$totalPage}页\\n自定义跳转到第几页:','');if(page>0&&page<$total)location.href=this.href+'='+(page-1);return false\">跳转</a></td>\n";
$re .= ( $currentPage > 0 )
? "<td><a href="\" mce_href="\""$url=0\">首页</a></td>\n<td><a href="\" mce_href="\""$url=".($currentPage-1)."\">上一页</a></td>\n"
: "<td>首页</td>\n<td>上一页</td>\n";
for ( $i = $currentPage - $halfPer,$i > 0 || $i = 0 , $j = $currentPage + $halfPer, $j < $totalPage || $j = $totalPage;$i < $j ;$i++ )
{
$re .= $i == $currentPage
? "<td><b class=currentPage>[" . ( $i + 1 ) . "]</b></td>\n"
: "<td><a href="\" mce_href="\""$url=$i\">" . ( $i + 1 ) . "</a></td>\n";
}
$re .= ( $currentPage < $total )
? "<td><a href="\" mce_href="\""$url=" . ( $currentPage + 1 ) . "\">下一页</a></td>\n<td><a href="\" mce_href="\""$url=" . ( $total )."\">尾页</a>\n</td>"
: "<td>下一页</td>\n<td>尾页</td>\n";
$re="<table style="text-align:center" mce_style="text-align:center"><tr>$re</tr></table>";
return $re;
}
?>
具体示例用法如下:
<?php
$totalPage = 100 ; //总分页数量
$currentPage = @$_GET['page']+0; //当前页码
$url = "?page"; //分而链接
$halfPer = 10; //二分之一的每页的信息数
$imagePath ="images"; //分页图片目录
$pageHtml = page ( $totalPage , $currentPage,$url ,$halfPer,$imagePath);//调用分页函数
echo $pageHtml ;
?&
相关文档:
[part1] http://download.csdn.net/source/2076258
[part2] http://download.csdn.net/source/2076272
[part3] http://download.csdn.net/source/2076276
[part4] http://download.csdn.net/source/2076283
[part02-04] http://www.ytgps.com/Images/nginx.rar
本文件体积过大分4个包,php-cgi+mysql+nginx.7z ......
PHP中设计模式的学习笔记
设计模式(Design Pattern)是面向对象设计中反复出现的问题的解决方案,设计模式是一种比一般类的设计更加抽象的一种思想,
它往往涉及到多个类的定义和使用。
在PHP的开发过程中,经常使用到得设计模式包括:简单工厂模式、单元素模式、观察者模式、命令模式、策略模式以及MVC模式等。
/ ......
<?php
//GB2312的Encode
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
/*重点了解strtotime()函数
1、strftime比time()好用,可以直接把常用的’2010-02-03‘转成时间戳。
2、date( ......
<?php
//--------------------
// 基本数据结构
//--------------------
//二分查找(数组里查找某个元素)
function bin_sch($arr, $low, $high, $k) {
if($low<=$high) {
$mid = intval(($low+$high)/2);
if($arr[$mid] == $k) {
return $mid;
} elseif($k<$ ......
//冒泡排序(数组中实现)
function bubble_sort($arr) {
$cnt = count($arr);
if($cnt<=0) return false;
for($i=0; $i<$cnt;$i++) {
for($j=$cnt-1; $j>$i;$j--) {
if($arr[$j]<$arr[$j-1]) {
$tmp = $arr[$j];
$arr[$j] = $arr[$j ......