Text data paging in php (message book paging)

Source: Internet
Author: User
Many pages are introduced in mysq, but few pages are introduced in the text data table format, here I will briefly introduce the following paging ideas: 1. paging of the message book 2. paging of the text Forum ------------------------ paging of the message book: -------------------- Many paging articles are introduced in mysq, the format of a text data table is rarely described in pages. here I will simply refer to pages.

This article mainly introduces the following paging ideas:
1. paging of the message book
2. flip pages of text forums

------------------------
Page flip of the message book:
------------------------------
This is the simplest page flip in a text data table.

Golbal file
Data. dat --- NOTE FILE USE
User. dat --- Forum File use
Data. dat
_______________________________________________________________________
[1] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[2] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[3] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[4] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[5] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]

Note:
[1, 2, 3, 4, 5...] is added by myself for better understanding.

Index. php source :.

__________________________________________________

--- === BOF ==== ---
$ File = "data. dat"; // data file
If (file_exits ($ file) {// fault tolerance processing to prevent the existence of non-data files
$ Fp = fopen ($ file, "w + ");
Fclose ($ fp );
Unset ($ fp );
}
$ Listnumber = 20; // Number of Entries displayed per page
$ Fp = file ($ file); // read data to the content
$ Number = count ($ fp); // calculates the total data volume
$ Pagenumber = floor ($ number/$ listnumber) + 1;
If ($ number <1 ){
Print "no record at the moment, please leave a message ";
/* + -------------------------------- +
| Print the FORM or link to the table here |
| URL, |
+ -------------------------------- + */
} Else {
If (empty ($ _ POST ["page"]) {// this section IF... ELSE... it is written to ensure compatibility with the default php4.20 settings and prevent invalid global variables.
$ Page = 0; // because it is read from the data text, it is saved in the array and has an O subscript.
} Else {
$ Page = $ _ POST ["page"]
}

If ($ page <0 | $ page> pagenumber) {// when the page parameter jumps out of the total page or is smaller than the homepage (0), it is returned to the first page.
$ Page = 0;
}

$ Startnote = $ page * $ listnumber; // start recording location
$ Endnote = $ startnote + $ listnumber; // end record location

// For ($ int_a = $ startnote; $ int_a <$ endnote; $ int_a ++) {// sorting display is similar to ASC mode

Pirnt"



"For ($ int_a = $ endnote; $ int_a >=$ startnote; $ int_a --) {// sort display is similar to DESC mode$ Info = explode ("\ t", $ fp [$ int-a]); // cut data to obtain detailed data for each record. here we use a TAB key to separatePrint"
User: $ info [1] Title $ info [2]: $ info [3] Release date: $ info [4] IP: $ info [5] ";
}

$ Prevpage = $ page-1; // Number of pages on the previous PAGE
$ Nextpage = $ page + 1; // Number of pages on the next page

Print"

Homepage
Previous Page
Next page
Last page
"; // You can directly add the page detection here, so that it is comfortable for others, but the effect is the same
// For example, the next page or
}
?>
--- ==== EOF ==== ---


In addition, many of them changed because PHP4.20 was used. for example, PHP_SELF has already used _ SERVER ["PHP_SELF, for details, refer to the Chinese description in the essence area to see the name.

The above is a description of the paging function for saving the message book data in text. For more details about page turning to a text Forum, I will write it out as soon as possible ....

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.