php 分页类_PHP教程

WBOY
Libérer: 2016-07-20 11:15:04
original
1067 Les gens l'ont consulté

<?<span php
</span><span /*</span><span 
 *本程序文件对分页程序进行了封装
 *
</span><span */</span>

<span class</span><span  Page_Link
{
    </span><span var</span> <span $page_max</span> = 10; <span //</span><span 一组页码的最大数</span>

    <span var</span> <span $page_num</span> = 10; <span //</span><span 总页数</span>
    <span var</span> <span $length</span> = 20; <span //</span><span 一页的数据条数</span>

    <span var</span> <span $isNextPage</span> = <span true</span><span ;
    </span><span var</span> <span $isFirstPage</span> = <span false</span><span ;

    </span><span function</span> Calculation_Page_Num( <span $total</span><span  )
    {
        </span><span $this</span>->page_num = <span ceil</span>( <span $total</span> / <span $this</span>-><span length );
        </span><span return</span> <span $this</span>-><span page_num;
    }

    </span><span function</span> Calculation_Min_Max( <span $act_page</span> = 1<span  )
    {
        </span><span //</span><span  定义左右偏移量</span>
        <span $py_left</span> = 0<span ;
        </span><span $py_right</span> = 0<span ;
        </span><span //</span><span  定义左右边界</span>
        <span $bj_left</span> = 0<span ;
        </span><span $bj_right</span> = 0<span ;
        </span><span //</span><span  定义滚动区间边界</span>
        <span $gd_left</span> = 0<span ;
        </span><span $gd_right</span> = 0<span ;
        </span><span //</span><span  判断是否需要分组</span>
        <span if</span> ( ( <span $this</span>->page_num - <span $this</span>->page_max ) <= 0<span  )
        {
            </span><span //</span><span  不需要分组</span>
            <span $bj_left</span> = 1<span ;
            </span><span $bj_right</span> = <span $this</span>-><span page_num;
        }
        </span><span else</span><span 
        {
            </span><span //</span><span  要进行分组
            // 判断容量的奇偶</span>
            <span $tmp</span> = <span $this</span>->page_max % 2<span ;
            </span><span if</span> ( <span $tmp</span> === 1<span  )
            {
                </span><span //</span><span  奇数</span>
                <span $py_left</span> = <span $py_right</span> = ( <span $this</span>->page_max - 1 ) / 2<span ;
            }
            </span><span else</span><span 
            {
                </span><span //</span><span  偶数</span>
                <span $py_left</span> = <span $this</span>->page_max / 2 - 1<span ;
                </span><span $py_right</span> = <span $this</span>->page_max / 2<span ;
            }
            </span><span //</span><span  计算滚动区间</span>
            <span $gd_left</span> = 1 + <span $py_left</span><span ;
            </span><span $gd_right</span> = <span $this</span>->page_num - <span $py_right</span><span ;
            </span><span //</span><span  判断当前页是否落入了滚动区间</span>
            <span if</span> ( <span $act_page</span> >= <span $gd_left</span> && <span $act_page</span> <= <span $gd_right</span><span  )
            {
                </span><span //</span><span  区间内</span>
                <span $bj_left</span> = <span $act_page</span> - <span $py_left</span><span ;
                </span><span $bj_right</span> = <span $act_page</span> + <span $py_right</span><span ;
            }
            </span><span else</span><span 
            {
                </span><span //</span><span  区间外</span>
                <span if</span> ( ( <span $act_page</span> - <span $py_left</span> ) <= 1<span  )
                {
                    </span><span //</span><span  左侧固定区间</span>
                    <span $bj_left</span> = 1<span ;
                    </span><span $bj_right</span> = <span $this</span>-><span page_max;
                }
                </span><span else</span><span 
                {
                    </span><span $bj_left</span> = <span $this</span>->page_num - <span $this</span>->page_max + 1<span ;
                    </span><span $bj_right</span> = <span $this</span>-><span page_num;
                }
            }
        }

        </span><span $res</span> = <span array</span><span ();
        </span><span $res</span>['min'] = <span $bj_left</span><span ;
        </span><span $res</span>['max'] = <span $bj_right</span><span ;

        </span><span return</span> <span $res</span><span ;
       </span><span 
    }
    </span><span //</span><span  主方法</span>
    <span function</span> make_page( <span $total</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $page_num</span> = <span $this</span>->Calculation_Page_Num( <span $total</span><span  );
        </span><span $arr_min_max</span> = <span $this</span>->Calculation_Min_Max( <span $act_page</span><span  );
        
        </span><span if</span> (!<span eregi</span>("([?|&]<span $param</span>=)", <span $url</span><span )) {
            </span><span $url</span> = <span strpos</span>(<span $url</span>,"?")===<span false</span>?<span $url</span>."?":<span $url</span>."&"<span ;
            </span><span $url</span> = <span $url</span>."<span $param</span>=0"<span ;
        }

        </span><span if</span> ( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span><span ;
        }
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );

        </span><span $res</span> = <span array</span><span ();
        </span><span $d</span> = 0<span ;
        </span><span for</span>( <span $i</span> = <span $arr_min_max</span>['min'];<span $i</span> <= <span $arr_min_max</span>['max'];<span $i</span>++<span  )
        {
            </span><span if</span> ( <span $i</span> == <span $act_page</span><span  )
            {
                </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
            }
            </span><span else</span><span 
            {
                </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
            }
            </span><span $d</span>++<span ;
        }

        </span><span if</span> ( <span $this</span>-><span isNextPage )
        {
            </span><span $res</span> = <span $this</span>->make_before_next_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        </span><span if</span> ( <span $this</span>-><span isFirstPage )
        {
            </span><span $res</span> = <span $this</span>->make_first_end_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        </span><span return</span> <span $res</span><span ;
    }
    </span><span //</span><span // 带总页数</span>
    <span function</span> make_page_with_total( <span $total</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $page_num</span> = <span $this</span>->Calculation_Page_Num( <span $total</span><span  );
        </span><span $arr_min_max</span> = <span $this</span>->Calculation_Min_Max( <span $act_page</span><span  );
        
        </span><span if</span> (!<span eregi</span>("([?|&]<span $param</span>=)", <span $url</span><span )) {
            </span><span $url</span> = <span strpos</span>(<span $url</span>,"?")===<span false</span>?<span $url</span>."?":<span $url</span>."&"<span ;
            </span><span $url</span> = <span $url</span>."<span $param</span>=0"<span ;
        }

        </span><span if</span> ( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span><span ;
        }
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );

        </span><span $res</span> = <span array</span><span ();
        </span><span $d</span> = 0<span ;
        </span><span for</span>( <span $i</span> = <span $arr_min_max</span>['min'];<span $i</span> <= <span $arr_min_max</span>['max'];<span $i</span>++<span  )
        {
            </span><span if</span> ( <span $i</span> == <span $act_page</span><span  )
            {
                </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
            }
            </span><span else</span><span 
            {
                </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
            }
            </span><span $d</span>++<span ;
        }

        </span><span if</span> ( <span $this</span>-><span isNextPage )
        {
            </span><span $res</span> = <span $this</span>->make_before_next_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        </span><span if</span> ( <span $this</span>-><span isFirstPage )
        {
            </span><span $res</span> = <span $this</span>->make_first_end_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        
        </span><span $total_num</span>= <span ceil</span>(<span $total</span>/<span $this</span>-><span length);
        </span><span $result</span>['total']=<span $total_num</span><span ;
        </span><span $result</span>['DATA']=<span $res</span><span ;
        </span><span return</span> <span $result</span><span ;
    }
    
    </span><span //</span><span  附加上一页和下一页</span>
    <span function</span> make_before_next_link( <span $arr</span>, <span $act</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $tmp</span> = <span array</span><span ();

        </span><span $before</span> = <span $act</span> - 1<span ;
        </span><span $next</span> = <span $act</span> + 1<span ;

        </span><span if</span> ( <span $before</span> < 1<span  )
        {
            </span><span $before</span> = 1<span ;
            </span><span $tmp</span>[0]['url'] = ''<span ;
            </span><span $tmp</span>[0]['name'] = "上一页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $before</span>, <span $url</span><span  );
            </span><span $tmp</span>[0]['name'] = "上一页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }

        </span><span $counts</span> = <span sizeof</span>( <span $arr</span><span  );
        </span><span $tmp_count</span> = <span sizeof</span>( <span $tmp</span><span  );
        </span><span for</span>( <span $i</span> = 0;<span $i</span> < <span $counts</span>;<span $i</span>++<span  )
        {
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = <span $arr</span>[<span $i</span>]['url'<span ];
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = <span $arr</span>[<span $i</span>]['name'<span ];
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $arr</span>[<span $i</span>]['no'<span ];
            </span><span $tmp_count</span>++<span ;
        }

        </span><span if</span> ( <span $next</span> > <span $this</span>-><span page_num )
        {
            </span><span $next</span> = <span $this</span>-><span page_num;
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = ''<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = "下一页"<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $next</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $next</span>, <span $url</span><span  );
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = "下一页"<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $next</span><span ;
        }

        </span><span return</span> <span $tmp</span><span ;
    }
    
    </span><span //</span><span  附加首页和尾页</span>
    <span function</span> make_first_end_link( <span $arr</span>, <span $act</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $tmp</span> = <span array</span><span ();

        </span><span $before</span> = 1<span ;
        </span><span $next</span> = <span $this</span>-><span page_num;

        </span><span if</span> ( <span $act</span> == 1<span  )
        {
            </span><span $before</span> = 1<span ;
            </span><span $tmp</span>[0]['url'] = ''<span ;
            </span><span $tmp</span>[0]['name'] = "首页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $before</span>, <span $url</span><span  );
            </span><span $tmp</span>[0]['name'] = "首页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }

        </span><span $counts</span> = <span sizeof</span>( <span $arr</span><span  );
        </span><span $tmp_count</span> = <span sizeof</span>( <span $tmp</span><span  );
        </span><span for</span>( <span $i</span> = 0;<span $i</span> < <span $counts</span>;<span $i</span>++<span  )
        {
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = <span $arr</span>[<span $i</span>]['url'<span ];
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = <span $arr</span>[<span $i</span>]['name'<span ];
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $arr</span>[<span $i</span>]['no'<span ];
            </span><span $tmp_count</span>++<span ;
        }

        </span><span if</span> ( <span $act</span> == <span $this</span>-><span page_num )
        {
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = ''<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = "尾页"<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $next</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[<span $tmp_count</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $next</span>, <span $url</span><span  );
            </span><span $tmp</span>[<span $tmp_count</span>]['name'] = "尾页"<span ;
            </span><span $tmp</span>[<span $tmp_count</span>]['no'] = <span $next</span><span ;
        }

        </span><span return</span> <span $tmp</span><span ;
    }
    
     
    </span><span /*</span><span *
     * 带上一页<,下一页>,省略号的分页
     * @param int $total        记录总条数
     * @param int $act_page        当前页码
     * @param string $url        url
     * @param int $maxpageicon    最大显示页码数
     * @param int $style        上一页,下一页显示样式
     * @param string $param        url参数
     </span><span */</span>
    <span function</span> make_page_with_points( <span $total</span>,<span $act_page</span>,<span $url</span>,<span $maxpageicon</span>,<span $style</span>,<span $param</span><span  )
    {
        </span><span $page_num</span> = <span $this</span>->Calculation_Page_Num( <span $total</span> );        <span //</span><span 总页数</span>
        <span $arr_min_max</span> = <span $this</span>->Calculation_Min_Max( <span $act_page</span> );        <span //</span><span 最大页,最小页    </span>
        <span if</span>(<span $total</span>==0<span )
        {
             </span><span return</span> ""<span ;

        }
        </span><span if</span>( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span>+1<span ;
            </span><span $page_num</span> = <span $page_num</span>+1<span ;
        }
        
        </span><span switch</span> (<span $style</span><span ){
            </span><span case</span> 1:
                <span $name_before</span> = '前一页'<span ;
                </span><span $name_next</span> = '后一页'<span ;
                </span><span break</span><span ;
            </span><span case</span> 2:
                <span $name_before</span> = '<'<span ;
                </span><span $name_next</span> = '>'<span ;
                </span><span break</span><span ;
            </span><span case</span> 3:
                <span $name_before</span> = '<<'<span ;
                </span><span $name_next</span> = '>>'<span ;
                </span><span break</span><span ;
            </span><span default</span>:
                <span $name_before</span> = '上一页'<span ;
                </span><span $name_next</span> = '下一页'<span ;
        }
        
        </span><span if</span> (!<span eregi</span>("([?|&]<span $param</span>=)", <span $url</span><span )) {
            </span><span $url</span> = <span strpos</span>(<span $url</span>,"?")===<span false</span>?<span $url</span>."?":<span $url</span>."&"<span ;
            </span><span $url</span> = <span $url</span>."<span $param</span>=0"<span ;
        }
                
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );
        </span><span $res</span> = <span array</span><span ();
        </span><span $no_before</span> = <span $act_page</span>-1<span ;
        </span><span $no_next</span> = <span $act_page</span>+1<span ;
        
        </span><span //</span><span 总页数如果小于等于初始化最大呈现页数</span>
        <span if</span> (<span $page_num</span><= (<span $maxpageicon</span> + 1<span ))
        {
            </span><span //</span><span 如果当前页数是首页  上一页无效</span>
            <span if</span> (<span $act_page</span> == 1<span )    
            {
                </span><span $res</span>[0]['url'] = ''<span ;
                </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
            }
            </span><span else</span>            <span //</span><span 上一页有效</span>
<span             {
                </span><span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                </span><span $res</span>[0]['no'] = <span $no_before</span><span ;  
            }
            </span><span //</span><span 循环添加页码</span>
            <span $d</span> = 1<span ;
            </span><span for</span> (<span $i</span> = 1; <span $i</span> <= <span $page_num</span>; <span $i</span>++<span )
            {
                </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                {
                    </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                    </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                }
                </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                 {
                    </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                    </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                }
                </span><span $d</span>++<span ;
            }
            </span><span $last_d</span> = <span count</span>(<span $res</span><span );
            </span><span //</span><span 判断尾页</span>
            <span if</span>(<span $act_page</span> == <span $page_num</span>)    <span //</span><span 下一页无效</span>
<span             {
                </span><span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;        
            }
            </span><span else</span><span 
            {
                  </span><span $res</span>[<span $last_d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> + 1), <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;
            }
        }</span><span else</span> <span if</span> (<span $page_num</span> > (<span $maxpageicon</span> + 1))<span //</span><span 如果总页数满足添加省略号</span>
<span         { 
            </span><span if</span> (<span $act_page</span> <= <span $maxpageicon</span>) <span //</span><span 如果当前页小于等于初始化数目</span>
<span             {
                </span><span //</span><span 如果当前页数是首页  上一页无效</span>
                <span if</span> (<span $act_page</span> == 1<span )    
                {
                    </span><span $res</span>[0]['url'] = ''<span ;
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                }
                </span><span else</span>            <span //</span><span 上一页有效</span>
<span                 {
                    </span><span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;  
                }
                </span><span //</span><span 循环添加页码</span>
                <span $d</span> = 1<span ;
                </span><span for</span> (<span $i</span> = 1; <span $i</span> <= <span $maxpageicon</span>; <span $i</span>++<span )
                {
                    </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                    {
                        </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                        </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                    }
                    </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                     {
                        </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                        </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                    }
                    </span><span $d</span>++<span ;
                }
                </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                </span><span //</span><span 添加省略号</span>
                <span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $last_d</span>]['name'] = '...'<span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = ''<span ;
                </span><span //</span><span 总页数</span>
                <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $page_num</span>, <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $page_num</span><span ;
                </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $page_num</span><span ;
                </span><span //</span><span 下一页</span>
                <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . (<span $act_page</span> + 1), <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $no_next</span><span ;         
            }</span><span else</span><span //</span><span 如果当前页大于最大显示页面</span>
<span             {
                </span><span if</span> (<span $act_page</span> > (<span $page_num</span> - <span $maxpageicon</span>))<span //</span><span 满足后几页</span>
<span                 {
                    </span><span //</span><span 上一页</span>
                    <span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                    </span><span //</span><span 第一页</span>
                    <span $res</span>[1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=1', <span $url</span><span  );
                    </span><span $res</span>[1]['name'] = 1<span ;
                    </span><span $res</span>[1]['no'] = 1<span ;   
                    </span><span //</span><span 省略号</span>
                    <span $res</span>[2]['url'] = ''<span ;
                    </span><span $res</span>[2]['name'] = '...'<span ;
                    </span><span $res</span>[2]['no'] = ''<span ;  
                    </span><span $d</span> = 3<span ;
                    </span><span for</span> (<span $i</span> = (<span $page_num</span> - <span $maxpageicon</span> + 1); <span $i</span> <= <span $page_num</span>; <span $i</span>++<span )
                    {
                        </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                        {
                            </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        }
                        </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                         {
                            </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                        }
                        </span><span $d</span>++<span ;
                    }
                    </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                    </span><span //</span><span 判断尾页</span>
                    <span if</span>(<span $act_page</span> == <span $page_num</span>)    <span //</span><span 下一页无效</span>
<span                     {
                          </span><span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                        </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                        </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;        
                    }
                    </span><span else</span><span 
                    {
                          </span><span $res</span>[<span $last_d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> + 1), <span $url</span><span  );
                        </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                        </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;
                    }

                }</span><span else</span><span //</span><span 满足处在中间</span>
<span                 {
                    </span><span //</span><span 上一页</span>
                    <span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                    </span><span //</span><span 第一页</span>
                    <span $res</span>[1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=1', <span $url</span><span  );
                    </span><span $res</span>[1]['name'] = 1<span ;
                    </span><span $res</span>[1]['no'] = 1<span ;   
                    </span><span //</span><span 省略号</span>
                    <span $res</span>[2]['url'] = ''<span ;
                    </span><span $res</span>[2]['name'] = '...'<span ;
                    </span><span $res</span>[2]['no'] = ''<span ;  
                    </span><span for</span> (<span $i</span> = (<span $act_page</span> - (<span $maxpageicon</span> - 2) / 2); <span $i</span> <= <span floor</span>(<span $act_page</span>+(<span $maxpageicon</span> - 2) / 2); <span $i</span>++<span )
                    {
                        </span><span $i</span> = <span ceil</span>(<span $i</span><span );
                        </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                        {
                            </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        }
                        </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                         {
                            </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                        }
                        </span><span $d</span>++<span ;
                   }
                    </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                    </span><span //</span><span 加省略号</span>
                    <span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                    </span><span $res</span>[<span $last_d</span>]['name'] = '...'<span ;
                    </span><span $res</span>[<span $last_d</span>]['no'] = ''<span ;
                    </span><span //</span><span 当前页</span>
                    <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $page_num</span>, <span $url</span><span  );
                    </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $page_num</span><span ;
                    </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $page_num</span><span ;        
                    </span><span //</span><span 下一页</span>
                    <span $res</span>[<span $last_d</span>+2]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . (<span $act_page</span> + 1), <span $url</span><span  );
                    </span><span $res</span>[<span $last_d</span>+2]['name'] = <span $name_next</span><span ;
                    </span><span $res</span>[<span $last_d</span>+2]['no'] = <span $no_next</span><span ;
                    </span><span //</span><span exit;    </span>
<span                  }
            }
        }
        </span><span return</span> <span $res</span><span ;
    }
}

</span>?>
Copier après la connexion

使用方法 :

<span $page_no</span> = <span $_GET</span>['page_no'] ? <span $_GET</span>['page_no'] : 1<span ;
</span><span $count</span> = 20<span ;
</span><span $start</span> = (<span $page_no</span>-1)*<span $count</span><span ;
</span><span $end</span> = <span $start</span> + <span $count</span><span ;
</span><span $page</span> = <span new</span><span  Page_Link();
</span><span $page</span>->length = <span $count</span><span ;
</span><span $page</span>->isFirstPage = <span true</span><span ;
</span><span $url</span> = <span $_SERVER</span>['SCRIPT_NAME']."?&a=".<span $a</span><span ;
</span><span $page_arr</span> = <span $page</span>->make_page(<span $total_num</span>,<span $page_no</span>,<span $url</span>,"page_no");
Copier après la connexion

支持多种样式:

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440232.htmlTechArticle? = 10; = 10; = 20; = = Calculation_Page_Num( -page_num = ( / - - Calculation_Min_Max( = 1 = 0 = 0 = 0 = 0 = 0 = 0 ( ( -page_num - -page_max ) = 0 = 1 = - = -page_max % 2 ( === 1 =...
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!