Paging code for text message book _ PHP Tutorial

Source: Internet
Author: User
The paging code of the text message book .? When writing a file, use | to separate each record. | used to separate each field in the record. for example, record 1 is represented as $ str1 $ name. |. $ pass. |. $ title. |. $ message. |. ......... Then connect // When writing a file, use "|" to separate each record. "|" is used to separate fields in the record.
// If Record 1 is $ str1 = $ name. "| ". $ pass. "| ". $ title. "| ". $ message. "| ". .........
// Connect to record 1 and record 2, $ str = $ str1. "|". $ str2. "||| ..........
// The Last generated file is as follows:
// Apsara Fox | 450948643 | this is the topic | this is the message content | 1 | Apsara Fox | 450948643 | this is the topic | this is the message content | 2 | | Apsara Fox | 450948643 | this is the topic | 3 | Apsara Fox | 450948643 | this is the topic | this is the message content | 4 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 5 | Apsara Fox | 450948643 | this is the topic | this is the message content | 6 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 7 | Apsara Fox | 450948643 | this is the topic | this is the message content | 8 | | Apsara Fox | 450948643 | this is the topic | 9 | Apsara Fox | 450948643 | this is the topic | this is the message content | 10 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 11 | Apsara Fox | 450948643 | this is the topic | this is the message content | 12 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 13 | Apsara Fox | 450948643 | this is the topic | this is the message content | 14 | | Apsara Fox | 450948643 | this is the topic | 15 | Apsara Fox | 450948643 | this is the topic | this is the message content | 16 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 17 | Apsara Fox | 450948643 | this is the topic | this is the message content | 18 | | Apsara Fox | 450948643 | this is the topic | 19 | Apsara Fox | 450948643 | this is the topic | this is the message content | 20 | | Apsara Fox | 450948643 | this is the topic | 21 | Apsara Fox | 450948643 | this is the topic | this is the message content | 22 | | Apsara Fox | 450948643 | this is the topic | this is the message content | 23 |
// Start to fetch the data in the file. the program list is as follows:
$ End = "|"; // record delimiter, depending on the symbol used to write the file
$ Mid = "|"; // field separator, same as above
$ Temp = file ("messageboard.info"); // read the file content into an array
$ Temp = join ("", $ temp); // Convert the read array into a string
$ Mess = explode ($ end, $ temp); // split the output record
$ Num = count ($ mess); // calculates the number of elements in the split string array, that is, the number of records.
If (! $ Dpage) $ dpage = 1; // stores the current page number
$ Row = 15; // The number of rows you want to display on each page
If ($ num/$ row = floor ($ num/$ row) $ page = $ num/$ row; // check whether an integer can be obtained. you can get an integer.
Else if ($ num/$ row> = floor ($ num/$ row) $ page = floor ($ num/$ row) + 1; // if the total number of items except the number of items on each page is greater than the number of items on each page, add one after the sum.
Else if ($ num/$ row <= floor ($ num/$ row) $ page = floor ($ num/$ row); // if it is smaller than the integer, get the integer
$ Minnum = ($ dpage-1) * $ row; // records are retrieved from this number of current pages
$ Maxnum = $ row * $ dpage; // maximum number of records to be retrieved on the current page
For ($ I = $ minnum; $ I <$ maxnum; $ I ++)
{
$ Message = explode ($ mid, $ mess [$ I]); // splits fields in the record
$ Num1 = count ($ message); // calculates the number of elements in the array to control loops.
For ($ j = 0; $ j <$ num1; $ j ++)
{
Echo $ message [$ j]. ""; // each time an element in the array is displayed.
}
Echo"
";
}
// Start paging below
If ($ page> = 2 & $ dpage = 1) // if the total number of pages is greater than two, and the current number is on the first page
{$ Paged = $ dpage + 1; echo "previous page
";}
Else if ($ page >=2 & $ dpage >=$ page) // if the total number of pages is greater than two and the current number is smaller than the total number of pages
{$ Pageu = $ dpage-1; echo "previous page
";}
Else if ($ page >=2 & $ dpage >=1 & $ dpage <$ page) // if the total number of pages is greater than two, and the current page is greater than one page and smaller than the total number of pages
{$ Pageu = $ dpage-1; $ paged = $ dpage + 1; echo "previous page
";}
// If there is only one page
Else echo "previous page
";
?>

[This article is copyrighted by the author and osuo. if you need to reprint it, please indicate the author and its source]

Http://www.bkjia.com/PHPjc/316272.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/316272.htmlTechArticle? // Used when writing a file | to separate each record | used to separate each field in the record. // for example, record 1 is represented as $ str1 = $ name. |. $ pass. |. $ title. |. $ message. |. ......... // Connect...

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.