By pairing
as we specify paging, 20 articles per page. There are 45 articles in a certain sub-channel list according to the database query. First, we obtain the following parameters through query: 1, the total number of pages; 2, the number of articles per page.
The second step of PHP processing of paging, for ($i = 0; $i < allpages; $i++), page element acquisition, analysis, and article generation are all executed in this loop. The difference is that the sentence die ("Create file".$filename."Success!"; is removed and placed in the display after the loop, because this statement will terminate program execution. Example:
- < ?php
- $fp = fopen ("temp.html","r");
- $content = fread ($fp,filesize ("temp.html"));
- $onepage = '20';
- $sql = "select id from article where
channel='$channelid'"; - $query = mysql_query ($sql);
- $num = mysql_num_rows ($query);
- $allpages = ceil ($num / $onepage);
- for ($i = 0;$i<$allpages; $i++){
- if ($i == 0){
- $indexpath = "index.html";
- } else {
- $indexpath = "index_".$i."html";
- }
- $start = $i * $onepage;
- $list = '';
- $sql_for_page = "select name,filename,title
from article where channel='$channelid'
limit $start,$onepage"; - $query_for_page = mysql_query ($sql_for_page);
- while ($result = $query_for_page){
- $list .= '.$root.$result['filename']
.'target=_blank>'.$title.'a> <br>';
-
}
-
$content = str_replace ( "{articletable}
",$list,$content);
- if (is_file ($indexpath)){
- @ unlink ($indexpath); //If the file already exists, delete it
- }
-
$ handle = fopen ($indexpath,"w");
//Open the file pointer and create the file
- /*
- Check if the file is created and writable
- */
- if (!is_writable ($indexpath)){
- echo "File: ".$indexpath." is not writable,
Please check Try again after its attribute! "; //Change to echo - }
- if (!fwrite ($handle,$content)) { //Write information to file
- echo "Generate file".$indexpath."Failed!"; //Change to echo
- }
- fclose ($handle); //Close pointer
- }
- fclose ($fp);
- die ("Generating the paging file is completed. If the generation is incomplete,
please check the file permission system and regenerate! "); -
?>
Approximately PHP The idea of handling paging is as follows. Other data generation, data input and output checking, paging content pointing, etc. can be added to the page as appropriate.
.
http://www.bkjia.com/PHPjc/445950.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445950.htmlTechArticleWhen pagination is specified by us, there are 20 articles per page. The database query of a certain sub-channel list contains 45 articles. First, we obtain the following parameters through query: 1. Total number of pages; 2. Each page...