PHP array-based paging function instance, php array paging instance _ PHP Tutorial

Source: Internet
Author: User
PHP provides array-based paging function instances and php array paging instances. PHP provides array-based paging function instances. the pagination function of php array paging instances is a very common function in PHP programming, this article introduces the array-based PHP paging function instance based on arrays and the PHP array paging instance.

The paging function is a very common function in PHP programming. unlike previous functions, this article introduces the array-based paging function of PHP.

With regard to the array paging function, the advantage of using arrays for paging is that it is convenient to perform combined multi-table queries, you only need to put the query results in an array. The following is an array paging function. the page_array function is used for array paging. the show_array function is used for paging function operation and display. it must be used in combination. The two functions are linked through the global variable $ countpage, which is used to track the total number of page numbers.

The specific instance code is as follows:

<? Php/*** array paging function core function array_slice * before using this function, you must first query all the data in the database in a certain order and store the data in the array * $ count how many entries per page data * $ page current page * $ all arrays queried by array * order 0-unchanged 1-Reverse order */function page_array ($ count, $ page, $ array, $ order) {global $ countpage; # set the global variable $ page = (empty ($ page ))? '1': $ page; # judge whether the current page is empty. if it is null, it indicates the first page $ start = ($ page-1) * $ count; # Calculate the start position of each page. if ($ order = 1) {$ array = array_reverse ($ array) ;}$ totals = count ($ array ); $ countpage = ceil ($ totals/$ count); # calculate the total number of pages $ pagedata = array (); $ pagedata = array_slice ($ array, $ start, $ count ); return $ pagedata; # return query data}/*** paging 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 page {$ countpage}/page {$ page}"; $ str. = "homepage"; $ str. = "previous page"; $ str. = "next page"; $ str. = "Last page"; $ str. ='

'; Return $ str ;}?>

We hope that the examples described in this article will provide some reference for everyone's PHP programming.


How to use PHP array to implement file paging


You did not < >, In the 39 chapters, a special chapter for file upload, very detailed, the simplest part is as follows:

POST method Upload

This feature allows users to upload text and binary files. Using PHP authentication and file operation functions, you can fully control which users are allowed to upload files and how to process the files after they are uploaded.

PHP is able to accept any files uploaded from RFC-1867-compliant browsers, including Netscape Navigator 3 and later, with patched Microsoft Internet Explorer 3 or later.

Related settings: see file_uploads, upload_max_filesize, upload_tmp_dirpost_max_size, and max_input_time settings in php. ini.

Note that PHP also supports file upload using the PUT method. this method is used by Netscape Composer and W3C Amaya clients. For more information, see support for the PUT method.

Example 39.1. file upload form

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








Send this file: >
 

How can php query oracle and display it by page? it is better to add a class instance.

The rownum code used to implement paging in oracle is 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 be used to implement paging query. of course, only SQL statements do not work. you can use the following PHP functions to implement paging.
/* Paging function */
Function page ($ page, $ total, $ phpfile, $ pagesize = 10, $ pagelen = 10, $ str = '')
{
$ Pagecode = ''; // defines variables and stores HTML generated by page.
$ Page = intval ($ page); // avoid non-numeric page numbers
$ Total = intval ($ total); // ensure that the total record value type is correct
If (! $ Total) return array (); // The total number of records is zero. an empty array is returned.
$ Pages = ceil ($ total/$ pagesize); // calculates the total page size.
// Process page validity
If ($ page <1) $ page = 1;
If ($ page> $ pages) $ page = $ pages;
// Calculate the query offset
$ Offset = $ pagesize * ($ page-1) + 1;
// Page number range calculation
$ Init = 1; // number of start page codes
$ Max = $ pages; // Number of ending pages
$ Pagelen = ($ pagelen % 2 )? $ Pagelen: $ pagelen + 1; // Number of page numbers
$ Pageoffset = ($ pagelen-1)/2; // page number offset between left and right
// Generate html
$ Pagecode ='

';
$ Pagecode. = "total ". $ total. "Information Section ". $ page. "page/total ". $ pages. "page </span> \ n"; // page number.
// If the first page is displayed, the connection between the first page and the previous page is not displayed.
If ($ page! = 1 ){
$ Pagecode. = "homepage </a>"; // The first page
$ Pagecode. = "previous page </a>"; // Previous Page
}
// Offset when the number of pages is greater than the number of pages
If ($ pages> $ pagelen)
{
// If the current page is less than or equal to the left offset
If ($ page <= $ pageoffset)
{
$ Init = 1;
$ Max = $ pagelen;
} Else
{
// For example,... the full text is left>
From UC Browser

The batch paging function is a very common function in PHP programming. unlike previous functions, this article introduces PHP based on arrays...

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.