Home > Backend Development > PHP Tutorial > 分享PHP函数实现数字与文字分页代码_PHP

分享PHP函数实现数字与文字分页代码_PHP

WBOY
Release: 2016-05-30 08:46:13
Original
1007 people have browsed it

这篇文章主要是用PHP函数实现数字与文字分页,具体实现步骤就不罗嗦了,直接上代码

/**
 * 
 * @param $_sql
 * @param $_size
 */

function _page($_sql,$_size) {
  //将里面的所有变量取出来,外部可以访问
  global $_page,$_pagesize,$_pagenum,$_pageabsolute,$_num;
  if (isset($_GET['page'])) {
    $_page = $_GET['page'];
    if (empty($_page) || $_page < 0 || !is_numeric($_page)) {
      $_page = 1;
    } else {
      $_page = intval($_page);
    }
  } else {
    $_page = 1;
  }
  $_pagesize = $_size;
  $_num = _num_rows(_query($_sql));
  if ($_num == 0) {
    $_pageabsolute = 1;
  } else {
    $_pageabsolute = ceil($_num / $_pagesize);
  }
  if ($_page > $_pageabsolute) {
    $_page = $_pageabsolute;
  }
  $_pagenum = ($_page - 1) * $_pagesize;
}


/**
 * _paging分页函数
 * @param $_type
 * @return 返回分页
 */

function _paging($_type) {
  global $_page,$_pageabsolute,$_num;
  if ($_type == 1) {
    echo '<div id="page_num">';
    echo '<ul>';
        for ($i=0;$i<$_pageabsolute;$i++) {
            if ($_page == ($i+1)) {
              echo '<li><a href="blog.php&#63;page='.($i+1).'" class="selected">'.($i+1).'</a></li>';
            } else {
              echo '<li><a href="blog.php&#63;page='.($i+1).'">'.($i+1).'</a></li>';
            }
        }
    echo '</ul>';
    echo '</div>';
  } elseif ($_type == 2) {
    echo '<div id="page_text">';
    echo '<ul>';
    echo '<li>'.$_page.'/'.$_pageabsolute.'页 | </li>';
    echo '<li>共有<strong>'.$_num.'</strong>个会员 | </li>';
        if ($_page == 1) {
          echo '<li>首页 | </li>';
          echo '<li> | </li>';
          echo '<li>尾页</li>';
        } else {
          echo '<li><a href="'.SCRIPT.'.php&#63;page='.($_page+1).'">下一页</a> | </li>';
          echo '<li><a href="'.SCRIPT.'.php&#63;page='.$_pageabsolute.'">尾页</a></li>';
        }
    echo '</ul>';
    echo '</div>';
  }
}

Copy after login

在核心函数库包装以上代码glob.funic.php

然后只要在文件中调用以下函数就行:

代码如下:


//_pageing函数调用分页,1|2,1表示数字分页,2表示文本分页
_paging(2);
?>

以上就是php函数实现数字与文字分页代码的全部内容,希望大家能够喜欢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template