http://community.csdn.net/Expert/topic/2865/2865562.xml?temp=.2724268
希望对你有帮助。。

解决方案 »

  1.   

    <script language="JavaScript">
    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>
    <?
    function turn($in,$offset,$up,$down)//$in,$offset-提取条数,$up-上一页字样,$down-下一页字样
    {
    if(empty($in))//提取量默认为30
        {
    $in=30;
        } 

    if (empty($offset)) //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0 
        {
    $offset=0; 
        }  

    $qh=mysql_query("select COUNT(*) AS rcnt FROM base WHERE reid='m' ORDER BY id DESC"); 
        $row=mysql_fetch_array($qh); 
        $nr=$row["rcnt"]; 
       
        //检查是否是最后一页 
        $upoffset=$offset-$in;
        if ($upoffset>=0) 
        {
    $rup="<a href=\"list.php?offset=$upoffset&in=$in\">$up</a> \n"; 
        }     //下一步,要写出到其它页面的链接 
        $preoffset=$offset+$in; 
        if($preoffset<$nr) //如果$preoffset的结果大于总条数,则不显示下一页(即已到最后一页)
        {
    $rdown="<a href=\"list.php?offset=$preoffset&in=$in\">$down</a> \n"; 
        }     $noffset=ceil($preoffset/$in);
        //计算总共需要的页数 
        $pages=ceil($nr/$in); //$pages变量现在包含所需的页数 
        $ss="<select name=\"menu1\" onChange=\"MM_jumpMenu('parent',this,0)\">";
        for ($i=0; $i <$pages; $i++) 
        {
    $newoffset=$in*$i; 
            $u=$i+1;
            $sed="";
            if($noffset==$u)
        {
    $sed="selected";
        }
    //echo  "<a href=\"list.php?offset=$newoffset\">$u</a> \n";//显示页数列表
        $cs[]="<option value=\"list.php?offset=$newoffset&in=$in\" $sed>$u</option> \n";
        }
        $fs="</select>";
    $c=implode('',$cs);
    $selectmenu=$ss."".$c."".$fs;
        
        return "$offset|||$in|||$rup|||$rdown|||$selectmenu|||$noffset|||$pages";
    //$offset,$in作为提取条数,$rup-上一页连接,$rdown-下一页连接,$selectmenu-跳转菜单,$noffset-当前页面,$pages-共几页
    }
    ?> 以前写的一个翻页功能函数
    贴出来,也希望高手指点一二
      

  2.   

    啊,忘了,呵呵
    $qh=mysql_query("select COUNT(*) AS rcnt FROM base WHERE reid='m' ORDER BY id DESC"); 应该改为
    $qh=mysql_query("select COUNT(*) AS rcnt FROM $tblname WHERE reid='m' ORDER BY id DESC"); 
      

  3.   

    给你一个类看看
    <?php
    class OPB
    {
        var $total;
        var $onepage;
        var $num;
        var $pagecount;
        var $total_page;
        var $offset;
        var $linkhead;    function opb($total, $onepage, $form_vars = '')
        {
            $pagecount        =& $_GET['pagecount'];
            $this->total      =& $total;
            $this->onepage    =& $onepage;
            $this->total_page =  ceil($total/$onepage);
            if ($pagecount=='')
            {
                $this->pagecount = 1;
                $this->offset    = 0;
            }
            else
            {
                $this->pagecount =& $pagecount;
                $this->offset    =  ($pagecount-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."=".$value;
                        $formlink =  $formlink.$addchar."&";
                    }
                }
            }
            else
            {
                $formlink = '';
            }        $linkarr = explode("pagecount=", $_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'>[1]</font>" : $char;
            if ($link==1)
            {
                return "<a href=\"$linkhead"."pagecount=1\" title=\"The first page\">$linkchar</a>";
            }
            else
            {
                return 1;
            }
        }
        #End of function first_page();    /**+-----------------------------------------------
        |    取得最末页.$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"."pagecount=$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;
            $pagecount =& $this->pagecount;
            if ($char=='')
            {
                $char = "[<]";
            }        if ($pagecount>1)
            {
                $pre_page = $pagecount - 1;
                return "<a href=\"$linkhead"."pagecount=$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;
            $pagecount  =& $this->pagecount;
            if ($char=='')
            {
                $char = "[>]";
            }
            if ($pagecount<$total_page)
            {
                $next_page = $pagecount + 1;
                return "<a href=\"$linkhead"."pagecount=$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;
            $pagecount =& $this->pagecount;
            $totalpage =& $this->total_page;
            $linkhead  =& $this->linkhead;
            $left      =  $left =='' ? "[" : $left;
            $right     =  $right=='' ? "]" : $right;
            $color     =  $color=='' ? "#ff0000" : $color;
            $minpage   =  ($pagecount-$mid)<1 ? 1 : $pagecount-$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==$pagecount)
                {
                    $char = "<font color='$color'>$chars</font>";
                }            $linkchar = "<a href='$linkhead"."pagecount=$i'>".$char."</a>";
                $linkbar .= $linkchar;
            }        return $linkbar;
        }
        #End of function num_bar();
      

  4.   

    /**+-----------------------------------------------
        |    取得上一组数字条.$char为链接的字符,默认为"[<<]"
        |    i.e. $pb        = new PageBar(50, 10);
        |        $num_bar   = $pb->num_bar();
        |         $pre_group = $pb->pre_group();
        |  +-----------------------------------------------
        */
        function pre_group($char='')
        {
            $pagecount   =& $this->pagecount;
            $linkhead    =& $this->linkhead;
            $num         =& $this->num;
            $mid         =  floor($num/2);
            $minpage     =  ($pagecount-$mid)<1 ? 1 : $pagecount-$mid;
            $char        =  $char=='' ? "[<<]" : $char;
            $pgpagecount =  $minpage>$num ? $minpage-$mid : 1;
            return "<a href='$linkhead"."pagecount=$pgpagecount' 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='')
        {
            $pagecount =& $this->pagecount;
            $linkhead  =& $this->linkhead;
            $totalpage =& $this->total_page;
            $num       =& $this->num;
            $mid       =  floor($num/2);
            $last      =  $num;
            $minpage   =  ($pagecount-$mid)<1 ? 1 : $pagecount-$mid;
            $maxpage   =  $minpage + $last;
            if ($maxpage > $totalpage)
            {
                $maxpage =& $totalpage;
                $minpage = $maxpage - $last;
                $minpage = $minpage < 1 ? 1 : $minpage;
            }        $char        = $char=='' ? "[>>]" : $char;
            $ngpagecount = ($totalpage>$maxpage+$last)? $maxpage + $mid : $totalpage;        return "<a href='$linkhead"."pagecount=$ngpagecount' title=\"next group number bar\">".$char."</a>";
        }
        #End of function next_group();    /**+-----------------------------------------------
        |    取得整个数字条,上一页,下一页,上一组
        |   下一组的等.$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'>[<]</font>") .$num_bar.$this->next_page("<font color='$maincolor'>[>]</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)."&nbsp;";
            $jump_form     = $this->jump_form($jump);
            return <<<EOT
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="right">$whole_num_bar</td>
        <td width="50" align="right">$jump_form</td>
      </tr>
    </table>
    EOT;
        }    /**+-----------------------------------------------
        |    跳转表单
        |   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;
            $form = <<<EOT
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <script language="javascript">
            function $jumpname(linkhead, total, page){            var pagecount = (page.value>total)?total:page.value;
                pagecount     = (pagecount<1)?1:pagecount;
                location.href = linkhead + "pagecount=" + pagecount;
                return false;
            }
        </script>
           <form name="$formname" method="post" onSubmit="return $jumpname('$linkhead', $total, $formname.page)"><tr>
              <td>
            <input name="page" type="text" size="1">
            <input type="button" name="Submit" value="GO" onClick="return $jumpname('$linkhead', $total, $formname.page)">
          </td>
            </tr></form></table>
    EOT;    return $form;
        }
        #End of function Jump_form();}
    #End of class PageBar;
    /****
        //example$total = 1000;
    $onepage = 20;$pb       = new OPB($total, $onepage, 'searchkey');
    $offset   = "offset=".$pb->offset();
    $pagebar1  = $pb->whole_bar();
    $pagebar2  = $pb->whole_bar(2, 19);
    $pagebar3  = $pb->whole_bar(3, 5, '#000000', '#cccccc');
    echo $offset."<br>".$pagebar1."<br>";
    echo $offset."<br>".$pagebar2."<br>";
    echo $offset."<br>".$pagebar3."<br>";
    */
    /** return:
       offset=0
    [1][<<][1][2][3][4][5][6][7][8][9][10][>][>>][50]*****/
    ?>