Php article list paging code how to write

Source: Internet
Author: User
How to write the paging code of the php article list? $ SQL & nbsp ;=& nbsp; "SELECT & nbsp; * & nbsp; FROM & nbsp; 'link' & nbsp; WHERE & nbsp; 'subdomain '& nbsp ;! = & Nbsp; ''& nbsp; ORDER & nbsp; BY & nb php article list paging code how to write?
$sql = "SELECT * FROM `links` WHERE `subdomain` != '' ORDER BY id desc LIMIT 100";
$rows = $db->getData($sql);
foreach($rows as $row)
{
echo '
  • '.$row['title'].'
  • ';
    }

    I will write the article on the first page, but I don't know how to write it if I need to paging it.
    Currently, the title subdomain field is available.
    ------ Solution --------------------
    You can directly find a paging function application.
    The approximate parameters are as follows:
    1 Total
    2 Current page
    3 page size
    4. baseUrl. The title and subdomain you mentioned are all transmitted in GET mode.
    5. display page quantity

    class CCustomWidgets {
      public static function Pager($totalPages, $pageNumber, $pageSize, $url, $displayNumber = 6) {
        $baseUrl = (strpos($url, "?") === false) ? $url.'?page=' : $url.'&page=';
        $pager = '
      ';

          $prevPage = $pageNumber - 1;
          if($prevPage > 0){
            $pager .= '
    • ??????é??
    • ';
          }

          if($totalPages - $pageNumber < $displayNumber) {
            $displayStart = ($totalPages >= $displayNumber) ? ($totalPages - $displayNumber + 1) : 1;
            $displayEnd = $totalPages;
          }else{
            if($pageNumber % $displayNumber){
              $displayStart = floor($pageNumber  / $displayNumber) * $displayNumber + 1;
              $displayEnd = (floor($pageNumber  / $displayNumber) + 1) * $displayNumber;
            }else{
              $displayStart = (floor(($pageNumber / $displayNumber) - 1)) * $displayNumber + 1;
              $displayEnd = (floor($pageNumber / $displayNumber)) * $displayNumber;
            }
          }


          for(; $displayStart <= $displayEnd; $displayStart++) {
            $pager .= '
    • '.$displayStart.'
    • ';
          }
          if($pageNumber < $totalPages){
            $pager .= '
    • ??????é??
    • ';
          }
          $pager .= "
    ";
        return $pager;
      }
    }



    ------ Solution --------------------
    These two fields are not enough if your paging is to be performed on the database. you only have part of the title and article. You must at least identify the domain as the segment/page of the article, and the id and title of the document can be repeated.

    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.