PHP based on the implementation of an array of pagination function instances, PHP array paging instance _php tutorial

Source: Internet
Author: User

PHP based on the implementation of an array of pagination function instances, PHP array Paging instance


Paging is a very common function in PHP programming, unlike in the past, this article is about PHP based on the implementation of the page paging function.

On the array of paging function, the advantage of using an array for paging is convenient for the Union of multiple table query, just want to put the results of the query in the array can be the following is the function of the array paging, function Page_array for the array of pagination, function Show_array for the operation and display of the paging function, Need to be used together. Two functions are linked by a global variable $countpage, which is used to track the total number of pages.

The specific instance code is as follows:

<?php/** * Number of Components page function core function Array_slice * Before using this function, all the data in the database must be queried in a certain order to be stored in the array * $count how many data per page * $page Current page * $array query All arrays * Order 0-Invariant 1-Reverse order */function Page_array ($count, $page, $array, $order) {global $countpage; #定全局变量 $page = (Empty ( $page))? ' 1 ': $page; #判断当前页面是否为空 if NULL is represented as the first 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; #返回查询数据}/** * Pagination and display function * $countpage global variable, write * $url current URL */function show_array ($countpage, $url) {$page =empty ($_get[' page ') ])? 1:$_get[' page '; if ($page > 1) {$uppage = $page-1;} else{$uppage =1;} if ($page < $countpage) {$nextpage = $page +1;}    else{$nextpage = $countpage;} $str = "; $str. = "Total {$countpage} page/{$page} page"; $str. = "Home Page"; $str. = "Previous Page"; $str. = "Next Page"; $str. = "last page"; $str. = '; return $str;}? >

It is hoped that the example mentioned in this paper can be used as a reference for PHP program design.


How to use PHP array to implement file paging


You have no < , the 39 chapters in the chapter, a special chapter to file upload, very detailed, the simplest part is as follows:

POST method Upload

This feature enables users to upload text and binary files. With PHP's authentication and file manipulation functions, you have full control over which people are allowed to upload and what to do with the file upload.

PHP can accept any uploaded files from browsers that meet the RFC-1867 standard (including Netscape Navigator 3 and later, patched Microsoft Internet Explorer 3 or later).

Related settings: See PHP.ini's File_uploads,upload_max_filesize,upload_tmp_dirpost_max_size and max_input_time settings options.

Note that PHP also supports the PUT method for file uploads, Netscape Composer and the Amaya client using this method. See support for the PUT method for more information.

Example 39.1. File Upload Form

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








Send This file: >

PHP How to implement query Oracle and then paged display, preferably a class plus instance, the

Oracle implementation paging uses the RowNum code 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 statement can implement paged query, of course, the light has SQL or not, with the following PHP function can be implemented paging.
/* Paging function */
Function page ($page, $total, $phpfile, $pagesize =10, $pagelen =10, $str = ")
{
$pagecode = ";//define variables to store page-generated HTML
$page = Intval ($page);//Avoid non-numeric page numbers
$total = Intval ($total);//Guaranteed Total record value type is correct
if (! $total) return array ();//The total number of records is zero returns an empty array
$pages = Ceil ($total/$pagesize);//Calculation of total pages
Handling page numbering legality
if ($page <1) $page = 1;
if ($page > $pages) $page = $pages;
Calculate Query Offset
$offset = $pagesize * ($page-1) +1;
Page range Calculation
$init = 1;//Start Page number
$max = $pages;//End page number
$pagelen = ($pagelen%2)? $pagelen: $pagelen +1;//page number
$pageoffset = ($pagelen-1)/2;//page number offset
Generate HTML
$pagecode = ";
$pagecode. = "total ". $total." Message ". $page." Page/Total ". $pages." Page </span>\n ";//page, total pages
If this is the first page, the connection to the first and previous pages is not displayed
if ($page!=1) {
$pagecode. = "Home </a>";//First page
$pagecode. = "Prev </a>";//prev
}
Can be offset when the number of pages is greater than the number
if ($pages > $pagelen)
{
If the current page is less than or equal to the left offset
if ($page <= $pageoffset)
{
$init = 1;
$max = $pagelen;
}else
{
Such as...... Remaining full text >>
From the UC Browser

http://www.bkjia.com/PHPjc/866675.html www.bkjia.com true http://www.bkjia.com/PHPjc/866675.html techarticle PHP based on the implementation of an array of pagination function instances, PHP array Paging instance paging is a very common function in PHP programming, unlike in the past, today this article is about the PHP array-based ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.