Php txt message board (paging function)

Source: Internet
Author: User

Php txt message board (paging function)

Php tutorial txt message board (paging function)

$ 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 ">


}


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.