<?
/* 分页类 */
class OPB
{
var $total;
var $onepage;
var $num;
var $page;
var $total_page;
var $offset;
var $linkhead; function opb($total, $onepage, $form_vars = '')
{
foreach ($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value) {
if ($_get_name != $this->offset) {
$this->_get_vars .= "&$_get_name=$_get_value";
}
}
// print $this->_get_vars;
$page =& $_GET['page'];
$this->total =& $total;
$this->onepage =& $onepage;
$this->total_page = ceil($total/$onepage);
if ($page=='')
{
$this->page = 1;
$this->offset = 0;
}
else
{
$this->page =& $page;
$this->offset = ($page-1)*$onepage;
}if ($form_vars != '')
{
$vars = explode("|", $form_vars);
$chk = $vars[0];
$chk2 = $vars[1];
$chk_value =& $_POST["$chk"];
$chk_value2 =& $_POST["$chk2"];
if ($chk_value=='' && $chk_value2=='')
{
$formlink = '';
}
else
{
for ($i=0; $i<sizeof($vars); $i++)
{
$var = $vars[$i];
$value =& $_POST["$var"];
$addchar = $var."=".urlencode($value);
$formlink = $formlink.$addchar."&";
}
}
}
else
{
$formlink = '';
}$linkarr = explode("page=", $_SERVER['QUERY_STRING']);
$linkft = $linkarr[0];
if ($linkft=='')
{
$this->linkhead = $_SERVER['PHP_SELF']."?".$formlink;
}
else
{
$linkft = substr($linkft, -1)=="&" ? $linkft : $linkft."&";
$this->linkhead = $_SERVER['PHP_SELF']."?".$linkft.$formlink;
}
}
#End of function PageBar();
**+-----------------------------------------------
| 用于取得select的指针.
| i.e. $pb = new PageBar(50, 10);
| $offset = $pb->offset();
| +-----------------------------------------------
*/
function offset()
{
return $this->offset;
}
#End of function offset();
/**+-----------------------------------------------
| 取得第一页.$link为1是为带链接
| i.e. $pb = new PageBar(50, 10);
| $first_page = $pb->first_page(1);
| +-----------------------------------------------
*/
function first_page($link='', $char='', $color='')
{
$linkhead =& $this->linkhead;
$linkchar = $char=='' ? "<font color='$color'>首页</font> " : $char;
if ($link==1)
{
return "<a href=\"$linkhead"."page=1\" title=\"The first page\">$linkchar</a>";
}
else
{
return 1;
}
}
#End of function first_page();
/* 分页类 */
class OPB
{
var $total;
var $onepage;
var $num;
var $page;
var $total_page;
var $offset;
var $linkhead; function opb($total, $onepage, $form_vars = '')
{
foreach ($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value) {
if ($_get_name != $this->offset) {
$this->_get_vars .= "&$_get_name=$_get_value";
}
}
// print $this->_get_vars;
$page =& $_GET['page'];
$this->total =& $total;
$this->onepage =& $onepage;
$this->total_page = ceil($total/$onepage);
if ($page=='')
{
$this->page = 1;
$this->offset = 0;
}
else
{
$this->page =& $page;
$this->offset = ($page-1)*$onepage;
}if ($form_vars != '')
{
$vars = explode("|", $form_vars);
$chk = $vars[0];
$chk2 = $vars[1];
$chk_value =& $_POST["$chk"];
$chk_value2 =& $_POST["$chk2"];
if ($chk_value=='' && $chk_value2=='')
{
$formlink = '';
}
else
{
for ($i=0; $i<sizeof($vars); $i++)
{
$var = $vars[$i];
$value =& $_POST["$var"];
$addchar = $var."=".urlencode($value);
$formlink = $formlink.$addchar."&";
}
}
}
else
{
$formlink = '';
}$linkarr = explode("page=", $_SERVER['QUERY_STRING']);
$linkft = $linkarr[0];
if ($linkft=='')
{
$this->linkhead = $_SERVER['PHP_SELF']."?".$formlink;
}
else
{
$linkft = substr($linkft, -1)=="&" ? $linkft : $linkft."&";
$this->linkhead = $_SERVER['PHP_SELF']."?".$linkft.$formlink;
}
}
#End of function PageBar();
**+-----------------------------------------------
| 用于取得select的指针.
| i.e. $pb = new PageBar(50, 10);
| $offset = $pb->offset();
| +-----------------------------------------------
*/
function offset()
{
return $this->offset;
}
#End of function offset();
/**+-----------------------------------------------
| 取得第一页.$link为1是为带链接
| i.e. $pb = new PageBar(50, 10);
| $first_page = $pb->first_page(1);
| +-----------------------------------------------
*/
function first_page($link='', $char='', $color='')
{
$linkhead =& $this->linkhead;
$linkchar = $char=='' ? "<font color='$color'>首页</font> " : $char;
if ($link==1)
{
return "<a href=\"$linkhead"."page=1\" title=\"The first page\">$linkchar</a>";
}
else
{
return 1;
}
}
#End of function first_page();
解决方案 »
- 这个问题:对不起,请将 php.ini 中的 short_open_tag 设置为 On,否则无法继续安装论坛。
- PHPCMS 中怎么做调用分页标签不显示效果了在线等.....麻烦知道的进!
- 请教PHP高手:程序需要同时访问MS-SQL数据库和MYSQL数据库,如何解决?
- mysql导入数据库命令.(简单问题)
- 1)safe_mode = Off ,但是 system 命令运行失败 2) linux命令下如何将目录下所以的目录和文件设置为777
- PEAR Cache_Lite如何将缓存保存到不同的文件夹中?
- 希望有朋友帮我理解这段程序~~~,我老觉得奇怪??学习
- 老大们,这是怎么回事啊?
- 在linux下,各位高手你们都用什么编辑器来写php代码啊?
- 含泪求一帮助,若此难不除,将无法下班又要到3点《获取图片真实地址》
- POST数组如何插入数据库中
- 求 针对新闻/帖子 点击计数 的思路
| 取得最末页.$link为1是为带链接
| i.e. $pb = new PageBar(50, 10);
| $total_page = $pb->total_page(1);
| +-----------------------------------------------
*/
function total_page($link='', $char='', $color='')
{
$linkhead =& $this->linkhead;
$total_page =& $this->total_page;
$linkchar = $char==''
? "<font color='$color'>[".$total_page."]</font>"
: $char;
if ($link==1)
{
return "<a href=\"$linkhead"."page=$total_page\" title=\"The lasted page\">$linkchar</a>";
}
else
{
return $total_page;
}
}
#End of function total_page();/**+-----------------------------------------------
| 取得上一页.$char为链接的字符,默认为"[<]"
| i.e. $pb = new PageBar(50, 10);
| $pre_page = $pb->pre_page("上一页");
| +-----------------------------------------------
*/
function pre_page($char='')
{
$linkhead =& $this->linkhead;
$page =& $this->page;
if ($char=='')
{
$char = "[<]";
}if ($page>1)
{
$pre_page = $page - 1;
return "<a href=\"$linkhead"."page=$pre_page\" title=\"previous page\">$char</a>";
}
else
{
return '';
}
}
#End of function pre_page();/**+-----------------------------------------------
| 取得下一页.$char为链接的字符,默认为"[>]"
| i.e. $pb = new PageBar(50, 10);
| $next_page = $pb->next_page("下一页");
| +-----------------------------------------------
*/
function next_page($char='')
{
$linkhead =& $this->linkhead;
$total_page =& $this->total_page;
$page =& $this->page;
if ($char=='')
{
$char = "[>]";
}
if ($page<$total_page)
{
$next_page = $page + 1;
return "<a href=\"$linkhead"."page=$next_page\" title=\"next page\">$char</a>";
}
else
{
return '';
}
}
#End of function next_page();
| 取得页码数字条. $num 为个数,默认为10
| $color 为当前链接的突显颜色
| $left 数字左边 默认为"["
| $right 数字左右 默认为"]"
| i.e. $pb = new PageBar(50, 10);
| $num_bar = $pb->num_bar(9, "$cccccc");
| +-----------------------------------------------
*/
function num_bar($num ='', $color='', $maincolor='', $left='', $right='')
{
$num = $num =='' ? 10 :$num;
$this->num =& $num;
$mid = floor($num/2);
$last = $num - 1;
$page =& $this->page;
$totalpage =& $this->total_page;
$linkhead =& $this->linkhead;
$left = $left =='' ? "[" : $left;
$right = $right=='' ? "]" : $right;
$color = $color=='' ? "#ff0000" : $color;
$minpage = ($page-$mid)<1 ? 1 : $page-$mid;
$maxpage = $minpage + $last;
if ($maxpage>$totalpage)
{
$maxpage =& $totalpage;
$minpage = $maxpage - $last;
$minpage = $minpage<1 ? 1 : $minpage;
}for ($i=$minpage; $i<=$maxpage; $i++)
{
$chars = $left.$i.$right;
$char = "<font color='$maincolor'>".$chars."</font>";
if ($i==$page)
{
$char = "<font color='$color'>$chars</font>";
}$linkchar = " <a href='$linkhead"."page=$i'>".$char."</a> ";
$linkbar .= $linkchar;
}return $linkbar;
}
#End of function num_bar();
/**+-----------------------------------------------
| 取得上一组数字条.$char为链接的字符,默认为"[<<]"
| i.e. $pb = new PageBar(50, 10);
| $num_bar = $pb->num_bar();
| $pre_group = $pb->pre_group();
| +-----------------------------------------------
*/
function pre_group($char='')
{
$page =& $this->page;
$linkhead =& $this->linkhead;
$num =& $this->num;
$mid = floor($num/2);
$minpage = ($page-$mid)<1 ? 1 : $page-$mid;
$char = $char=='' ? "[<<]" : $char;
$pgpage = $minpage>$num ? $minpage-$mid : 1;
return "<a href='$linkhead"."page=$pgpage' title=\"previous group number bar\">".$char."</a>";
}
#End of function pre_group();/**+-----------------------------------------------
| 取得下一组数字条.$char为链接的字符,默认为"[>>]"
| i.e. $pb = new PageBar(50, 10);
| $num_bar = $pb->num_bar();
| $next_group = $pb->next_group();
| +-----------------------------------------------
*/
function next_group($char='')
{
$page =& $this->page;
$linkhead =& $this->linkhead;
$totalpage =& $this->total_page;
$num =& $this->num;
$mid = floor($num/2);
$last = $num;
$minpage = ($page-$mid)<1 ? 1 : $page-$mid;
$maxpage = $minpage + $last;
if ($maxpage > $totalpage)
{
$maxpage =& $totalpage;
$minpage = $maxpage - $last;
$minpage = $minpage < 1 ? 1 : $minpage;
}$char = $char=='' ? "[>>]" : $char;
$ngpage = ($totalpage>$maxpage+$last)? $maxpage + $mid : $totalpage;return "<a href='$linkhead"."page=$ngpage' title=\"next group number bar\">".$char."</a>";
}
#End of function next_group();
过程:把选择出来的数据保存到数组里,比如$user_array,每行的$user_array[n]['total']就是全部数据的数量这样使用:
make_page_link($num, $per_page,$condition = '', $link_style = 0)
定义每页显示的数量:$per_page = 5;
先输出翻页:echo make_page_link($user_array[0]['total'], $per_page);
然后输出所选择的数据:
for($i = 0; $i < 20; $i++)
{
// 在这里循环输出数据
}大概的逻辑就是如此~
| 取得整个数字条,上一页,下一页,上一组
| 下一组的等.$num数字个数,$color 当前链接的突显色
| i.e. $pb = new PageBar(50, 10);
| $whole_num_bar = $pb->whole_num_bar(9);
| +-----------------------------------------------
*/
function whole_num_bar($num='', $color='', $maincolor='')
{
$num_bar = $this->num_bar($num, $color, $maincolor);return $this->first_page(1, '', $maincolor).
$this->pre_group(" <font color=\"$maincolor\">上一列</font> ").
$this->pre_page(" <font color=\"$maincolor\"><i><<</i></font> ") .
$num_bar.
$this->next_page(" <font color=\"$maincolor\"><i>>></i></font> ").
$this->next_group(" <font color=\"$maincolor\">下一列</font> ").
$this->total_page(1, '', $maincolor);
}
#End of function whole_bar();
/**+-----------------------------------------------
| 取得整链接,等于whole_num_bar加上表单跳转.
| $num数字个数,$color 当前链接的突显色
| i.e. $pb = new PageBar(50, 10);
| $whole_bar = $pb->whole_bar(9);
| +-----------------------------------------------
*/
function whole_bar($jump='', $num='', $color='', $maincolor='')
{
$whole_num_bar = $this->whole_num_bar($num, $color, $maincolor)." ";
$jump_form = $this->jump_form($jump);
return " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n".
" <tr>\n".
" <td align=\"right\">"."共 "."$this->total"." 条记录 "."$whole_num_bar</td>\n".
" <td width=\"50\" align=\"right\">$jump_form</td>\n".
" </tr>\n".
" </table>\n";
}/**+-----------------------------------------------
| 跳转表单
| i.e. $pb = new PageBar(50, 10);
| $Jump_form = $pb->Jump_form();
| +-----------------------------------------------
*/
function Jump_form($jump = '')
{
$formname = "pagebarjumpform".$jump;
$jumpname = "jump".$jump;
$linkhead = $this->linkhead;
$total = $this->total_page;
return "<table width=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n".
"<script language=\"javascript\">\n".
" function $jumpname(linkhead, total, page)\n".
" {\n".
" var page = (page.value>total)? total : page.value;\n".
" page = (page<1)? 1 : page; \n".
" location.href = linkhead + \"page=\" + page;\n".
" return false;\n".
" }\n".
"</script>\n".
"<form name=\"$formname\" method=\"post\" onSubmit=\"return $jumpname('$linkhead', $total, $formname.page)\">\n".
" <tr>\n".
" <td> 第\n".
" <input name=\"page\" type=\"text\" size=\"1\">页 \n".
" <input type=\"button\" name=\"Submit\" value=\"GO\" onClick=\"return $jumpname('$linkhead', $total, $formname.page)\">\n".
" </td>\n".
" </tr>\n".
"</form>\n".
"</table>\n";
}
#End of function Jump_form();
}
#End of class PageBar;?>