Home > Backend Development > PHP Tutorial > PHP array-based paging function example, PHP array paging example_PHP tutorial

PHP array-based paging function example, PHP array paging example_PHP tutorial

WBOY
Release: 2016-07-13 10:20:31
Original
1352 people have browsed it

PHP array-based paging function example, PHP array paging example

The paging function is a very common function in PHP programming. Different from the past, today’s article introduces the paging function implemented by PHP based on arrays.

Regarding the paging function of arrays, the advantage of using arrays for paging is that it is convenient to perform joint multi-table queries. You only need to put the query results in the array. The following is the function of array paging. The function page_array is used for arrays. For paging, the function show_array is used for the operation and display of paging functions and needs to be used together. The two functions are connected through the global variable $countpage, which is used to track the total number of pages.

The specific example code is as follows:

<&#63;php
/**
 * 数组分页函数 核心函数 array_slice
 * 用此函数之前要先将数据库里面的所有数据按一定的顺序查询出来存入数组中
 * $count  每页多少条数据
 * $page  当前第几页
 * $array  查询出来的所有数组
 * order 0 - 不变   1- 反序
 */ 
function page_array($count,$page,$array,$order){
  global $countpage; #定全局变量
  $page=(empty($page))&#63;'1':$page; #判断当前页面是否为空 如果为空就表示为第一页面 
    $start=($page-1)*$count; #计算每次分页的开始位置
  if($order==1){
   $array=array_reverse($array);
  }  
  $totals=count($array); 
  $countpage=ceil($totals/$count); #计算总页面数
  $pagedata=array();
 $pagedata=array_slice($array,$start,$count);
  return $pagedata; #返回查询数据
}
/**
 * 分页及显示函数
 * $countpage 全局变量,照写
 * $url 当前url
 */
function show_array($countpage,$url){
   $page=empty($_GET['page'])&#63;1:$_GET['page'];
 if($page > 1){
   $uppage=$page-1;
 }else{
  $uppage=1;
 }
 if($page < $countpage){
   $nextpage=$page+1;

 }else{
   $nextpage=$countpage;
 }
    $str='<div style="border:1px; width:300px; height:30px; color:#9999CC">';
 $str.="<span>共 {$countpage} 页 / 第 {$page} 页</span>";
 $str.="<span><a href='$url&#63;page=1'>  首页 </a></span>";
 $str.="<span><a href='$url&#63;page={$uppage}'> 上一页 </a></span>";
 $str.="<span><a href='$url&#63;page={$nextpage}'>下一页 </a></span>";
 $str.="<span><a href='$url&#63;page={$countpage}'>尾页 </a></span>";
 $str.='</div>';
 return $str;
}
&#63;>

Copy after login

I hope the examples described in this article can serve as a reference for everyone’s PHP programming design.

How to use PHP arrays to implement file paging


Don’t you have the <>, there are 39 chapters in it, one chapter is dedicated to file uploading, very detailed, the simplest part is as follows:

POST method Upload

This feature allows users to upload text and binary files. Using PHP's authentication and file operation functions, you can fully control who is allowed to upload and how the file is processed after it is uploaded.

PHP can accept files uploaded from any browser that complies with the RFC-1867 standard (including Netscape Navigator 3 and above, patched Microsoft Internet Explorer 3 or above).

Related settings: Please refer to the file_uploads, upload_max_filesize, upload_tmp_dirpost_max_size and max_input_time setting options of php.ini.

Please note that PHP also supports the PUT method of file upload, which is used by Netscape Composer and the W3C's Amaya client. See Support for the PUT method for more information.

Example 39.1. File upload form

You can create a special form to support file upload as follows:

 






Send this file:

How to query oracle in php and then display it in pages? It is best to use a class plus an instance,

Oracle uses rownum code to implement paging as follows
select * from (select t.* rownum row_id form (select * from table name) t ) where row_id>=1 and row_id<=10
This SQL statements can implement paging queries. Of course, SQL alone is not enough. You can use the following PHP function to implement paging.
/*Paging function*/
function page($page,$total,$phpfile,$pagesize=10,$pagelen=10,$str='')
{
$pagecode = '';//Define variables to store the HTML generated by paging
$page = intval($page);//Avoid non-numeric page numbers
$total = intval($total);//Ensure total record value type Correct
if(!$total) return array();//If the total number of records is zero, return an empty array
$pages = ceil($total/$pagesize);//Calculate the total paging
// Processing page number validity
if($page<1) $page = 1;
if($page>$pages) $page = $pages;
//Calculate query offset
$ offset = $pagesize*($page-1)+1;
//Page range calculation
$init = 1;//Starting page number
$max = $pages;//Ending page number
$pagelen = ($pagelen%2)?$pagelen:$pagelen+1;//Number of page numbers
$pageoffset = ($pagelen-1)/2;//Offset to the left and right of page number
//Generate html
$pagecode='

';
$pagecode.="A total of ".$total." information ". $page."pages/total".$pages."page\n";//Which page, how many pages in total
//If it is the first page, the first page and Link to previous page
if($page!=1){
$pagecode.=" Home page ";//First page
$pagecode.="
Previous page ";//Previous page
}
//When the number of pages is greater than the number of pages, it can be offset
if($pages>$pagelen)
{
//If the current page is less than or equal to the left offset
if($page<=$pageoffset)
{
$init=1;
$max = $pagelen;
}else
{
//If...the rest of the text>>
From UC Browser

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/866675.htmlTechArticlePHP array-based paging function example, php array paging example paging function is a very common function in PHP programming , different from the past, today’s article introduces PHP based on arrays...
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