Through the
If we specify paging, 20 articles per page. A sub-channel list of the article through the database query for 45, then, we first through the query to obtain the following parameters: 1, the total number of pages, 2, per page.
PHP processing Paging The second step, for ($i = 0; $i < allpages; $i + +), page element acquisition, analysis, article generation, are executed in this loop. The difference is that die ("Create file". $filename. " Success! This sentence is removed and placed on the display after the loop, because the statement aborts the execution of the program. Cases:
- < ? PHP
- $ FP = fopen ("temp.html", "R");
- $ content = fread ($FP, FileSize ("temp.html"));
- $ Onepage = ' A ' ;
- $ 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 the
- }
- $ Handle = fopen ($indexpath, "w");
Open file pointer, create file
- /*
- Check if the file is created and writable
- */
- if (!is_writable ($indexpath)) {
- echo "File:". $indexpath. " Not writable,
Please check its properties and try again! "; Modify to Echo
- }
- if (!fwrite ($handle, $content)) {//write information to file
- echo "Generate file". $indexpath. " Failed! "; Modify to Echo
- }
- Fclose ($handle); Close pointer
- }
- Fclose ($FP);
- Die ("Raw content Page file complete, if not complete,
Please check the file permissions system and regenerate! ");
- ?>
Roughly the way PHP handles paging, such as 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/445950.html techarticle 20 articles per page when paging is assigned to us. A sub-channel list of the article through the database query for 45, then, we first through the query to get the following parameters: 1, the total number of pages, 2, per page ...