Home  >  Article  >  Backend Development  >  About the paging code of text guestbook_PHP tutorial

About the paging code of text guestbook_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:16819browse

//When writing a file, use "|||" to separate each record, and "||" to separate each field in the record
//For example, record one is represented as $str1= $name."||".$pass."||".$title."||".$message."||".…………
//Then use it when connecting record one and record two, $str=$str1."|||".$str2."|||.......
//The final generated file is as follows
//Flying Fox||450948643||This is the theme|| This is the message content||1|||Flying Fox||450948643||This is the topic||This is the message content||2|||Flying Fox||450948643||This is the topic||This is the message content|| 3|||Flying Fox||450948643||This is the topic||This is the message content||4|||Flying Fox||450948643||This is the topic||This is the message content||5|||Flying Fox ||450948643||This is the topic||This is the message content||6|||Flying Fox||450948643||This is the topic||This is the message content||7|||Flying Fox||450948643||This is the topic||This is the message content||8|||Flying Fox||450948643||This is the topic||This is the message content||9|||Flying Fox||450948643||This is the topic||This is Message content||10|||Flying Fox||450948643||This is the topic||This is the message content||11|||Flying Fox||450948643||This is the topic||This is the message content||12| ||Flying Fox||450948643||This is the topic||This is the message content||13|||Flying Fox||450948643||This is the topic||This is the message content||14|||Flying Fox|| 450948643||This is the topic||This is the message content||15|||Flying Fox||450948643||This is the topic||This is the message content||16|||Flying Fox||450948643||This is the topic ||This is the message content||17|||Flying Fox||450948643||This is the topic||This is the message content||18|||Flying Fox||450948643||This is the topic||This is the message content ||19|||Flying Fox||450948643||This is the topic||This is the message content||20|||Flying Fox||450948643||This is the topic||This is the message content||21||| Flying Fox||450948643||This is the topic||This is the message content||22|||Flying Fox||450948643||This is the topic||This is the message content||23|||
//Then Start fetching the data in the file, the program list is as follows
$end="|||"; //Record separator, depending on the symbol used when writing the file
$mid="||"; // Field delimiter, same as above
$temp=file("messageboard.info"); //Read the file content into the array
$temp=join("",$temp); //The array to be read Become a string
$mess=explode($end,$temp); //Split the record
$num=count($mess); //Calculate the number of split string array elements, which is the record Number
if (!$dpage) $dpage=1; //Storage 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; // See if you can get an integer, you can take
Else if ($ num/$ row & gt; = Floor ($ num/$ $ ($ num/$ row)) $page=floor($num/$row)+1; //If the total number divided by the number of rows per page is greater than the number of requests, round it up and add one.
else if ($num/$row<=floor($num/$row)) $page=floor($num/$row); //If it is smaller than rounding, round it up
$minnum =($dpage-1)*$row; //The current page starts fetching records from this number
$maxnum=$row*$dpage; $minnum;$i<$maxnum;$i++)
{
$message=explode($mid,$mess[$i]); //Split out the fields in the record
$num1=count ($ Message); // Calculate the number of elements in the array to control the loop
for ($ j = 0; $ j & lt; $ num1; $ j ++)
{
echo $ message [$ j] ." "; //Display one element in the array at a time.
                                                                                                                                                                             Two pages, and if you are currently on the first page
{ $paged=$dpage+1; echo "Previous pageNext page
"; }
else if ($page>=2&&$dpage>=$page) //If the total number of pages is greater than two pages , and the current page is less than the total number of pages
{ $pageu=$dpage-1; echo "Previous pageNext page

"; }
else if ($page>=2&&$dpage>=1&&$dpage<$page) // If the total number of pages is greater than two pages, and the current page is greater than one and less than the total number of pages
{ $pageu=$dpage-1;$paged=$dpage+1;echo "
Previous page Previous page< br>";}
//If there is only one page
else echo "Previous pagePrevious page
";
?>

[The copyright of this article is jointly owned by the author and Aosuo.com. If you need to reprint, please indicate the author and source]




http://www.bkjia.com/PHPjc/316272.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/316272.htmlTechArticle? //Use ||| to separate each record when writing files, || is used to separate records Each field in //For example, record one is expressed as $str1=$name.||.$pass.||.$title.||.$message.||.……… //Then connect...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn