<?
/* 分页类 */
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();

解决方案 »

  1.   

    **+-----------------------------------------------
    | 取得最末页.$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();
      

  2.   

    /**+-----------------------------------------------
    | 取得页码数字条. $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();
      

  3.   

    MySQL分页简单的多了,但是MSSQL……不熟啊~不清楚了……
      

  4.   

    wangnian11(江湖人生) 你这个类发完了没有?
      

  5.   

    http://rodney-gu.blog.sohu.com/38355225.html
      

  6.   

    kapil() 你的这个分页函数没有处理数据库的部分阿?
      

  7.   

    sql语句:select count(user_id) as total, user_name from user_table limit 0, 20
    过程:把选择出来的数据保存到数组里,比如$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++)
    {
        // 在这里循环输出数据
    }大概的逻辑就是如此~
      

  8.   

    把上面的“make_page_link($num, $per_page,$condition = '', $link_style = 0)”改成那个函数的代码~~~
      

  9.   

    大哥我市sqlserver的数据库不是mysql所以没有limit 你看看清楚哦
      

  10.   

    ms sql sever也应该有办法实现的,呵呵
      

  11.   

    /**+-----------------------------------------------
    | 取得整个数字条,上一页,下一页,上一组
    | 下一组的等.$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\">"."共&nbsp;&nbsp;"."$this->total"."&nbsp;&nbsp;条记录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"."$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> &nbsp;&nbsp; 第\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;?>
      

  12.   

    wangnian11(江湖人生)大哥你的例子能不能给一个DEMO看看我还不知道你这个怎么用