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 format of text data tables. Here I will briefly 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 "<table>"

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 separate
Print "<tr> <td> User: $ info [1] title $ info [2] content: $ 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 "<tr> <td>
<A href = \ "$ _ SERVER [" PHP_SELF "]? Page = 0 \ "> homepage </a>
<A href = \ "$ _ SERVER [" PHP_SELF "]? Page = $ prevpage \ "> previous page </a>
<A href = \ "$ _ SERVER [" PHP_SELF "]? Page = $ nextpage \ "> next page </a>
<A href = \ "$ _ SERVER [" PHP_SELF "]? Page = $ pagenumber \ "> last page </a>
</Table> "; // here, You can directly add the page detection here. It is comfortable for others, but the effect is the same.
// For example, <a href = "index. php? Page = 21 "> next page </a> or <a href =" index. php? Page =-1 ">
}
?>
--- ==== EOF ==== ---


In addition, many of them changed because PHP4.20 was used. For example, PHP_SELF has already used _ SERVER ["PHP_SELF "].

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.