Using correlation functions to implement PHP processing paging _php Tutorial

Source: Internet
Author: User
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:

  1. < ? PHP
  2. $ FP = fopen ("temp.html", "R");
  3. $ content = fread ($FP, FileSize ("temp.html"));
  4. $ Onepage = ' A ' ;
  5. $ SQL = "SELECT ID from article where
    Channel= ' $channelid ' ";
  6. $ Query = mysql_query ($sql);
  7. $ Num = mysql_num_rows ($query);
  8. $ Allpages = Ceil ($num/$onepage);
  9. For ($i = 0; $i<$allpages; $i + +) {
  10. if ($i = = 0) {
  11. $ Indexpath = "Index.html" ;
  12. } else {
  13. $ Indexpath = "Index_" . $i. " HTML ";
  14. }
  15. $ Start = $i * $onepage;
  16. $ List = '' ;
  17. $ Sql_for_page = "Select Name,filename,title
    From article where channel= ' $channelid '
    Limit $start, $onepage ";
  18. $ Query_for_page = mysql_query ($sql _for_page);
  19. While ($result = $query _for_page) {
  20. $list . = ' . $root. $result [' filename ']
    .' Target = _blank > '. $title. ' a><br> ';
  21. }
  22. $ content = Str_replace ("{articletable}
    ", $list, $content);
  23. if (Is_file ($indexpath)) {
  24. @unlink ($indexpath); If the file already exists, delete the
  25. }
  26. $ Handle = fopen ($indexpath, "w");
    Open file pointer, create file
  27. /*
  28. Check if the file is created and writable
  29. */
  30. if (!is_writable ($indexpath)) {
  31. echo "File:". $indexpath. " Not writable,
    Please check its properties and try again! "; Modify to Echo
  32. }
  33. if (!fwrite ($handle, $content)) {//write information to file
  34. echo "Generate file". $indexpath. " Failed! "; Modify to Echo
  35. }
  36. Fclose ($handle); Close pointer
  37. }
  38. Fclose ($FP);
  39. Die ("Raw content Page file complete, if not complete,
    Please check the file permissions system and regenerate! ");
  40. ?>

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 ...

  • 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.