PHP Chinese data page (Message Book page) _php Foundation

Source: Internet
Author: User
Tags error handling
In the mysq to introduce a lot of pages, and text data table-style page of the introduction of little, here I simply say the page

Mainly introduce the following page-flipping ideas
1, the page of the message book
2, the Text forum page

————————————————————————
The page of the message book:
——————————————————————————————
This page in the text datasheet is the easiest page to flip, which means

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]

Description
of which [1,2,3,4,5 ...] I added it myself, mainly for the better understanding

index.php Source:.

__________________________________________________

---====bof====---
?
$file = "Data.dat"; Data files
if (File_exits ($file)) {//fault tolerant processing to prevent the existence of no data files
$FP =fopen ($file, "w+");
Fclose ($FP);
Unset ($FP);
}
$listnumber = 20; Show number of bars per page
$fp = file ($file); reading data to content
$number = count ($fp); Calculate the total amount of data
$pagenumber = Floor ($number/$listnumber) +1;
if ($number <1) {
Print "Temporarily no record, welcome message";
/*+--------------------------------+
| print form form or connect to table here but |
| URL, |
+--------------------------------+*/
}else{
if (Empty ($_post["page")) {//This paragraph if ... ELSE ... is intended to be compatible with the default settings of php4.20 to prevent invalid global variables from being written
$page = 0; Because it is read from the data text, saved in the array, there is an O subscript
}else{
$page = $_post["page"]
}

if ($page <0 | | | $page >pagenumber) {//error handling, when page parameters jump out of the total page or less than the first page (0), will return to the top
$page = 0;
}

$startnote = $page * $listnumber; Start record position
$endnote = $startnote + $listnumber; End Record Location

For ($int _a= $startnote; $int _a< $endnote; $int _a++) {//Sort display like ASC mode

Pirnt "<table>"

For ($int _a= $endnote; $int _a>= $startnote; $int _a--) {//Sort displays similar desc mode
$info =explode ("T", $fp [$int-a]); Cutting data to obtain detailed data for each record I'm using a TAB key to split
Print <tr><td> users: $info [1] title $info[2] Content: $info [3] Published: $info [4] IP: $info [5];
}

$prevpage = $page-1; Page number of previous page
$nextpage = $page +1; Page number of the next page

Print "<tr><td>
<a href=\ "$_server[" php_self "]?page=0\" > Home </a>
<a href=\ "$_server[" php_self "]?page= $prevpage \" > Prev </a>
<a href=\ "$_server[" php_self "]?page= $nextpage \" > next page </a>
<a href=\ "$_server[" php_self "]?page= $pagenumber \" > End </a>
</table> "; Here you can add the page to the test directly here, that gives others to see is comfortable, but the effect is the same
For example: There may be 20 pages appearing <a href= "index.php?page=21" > next page </a> or <a href= "Index.php?page=-1" >
}
?>
---====eof====---


Write hastily, the other in the middle there are many because of the use of PHP4.20 so change a bit, for example, Php_self has adopted _server["php_self"] and so on

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.