A "common" query paging class that can query all tables in PHP

Source: Internet
Author: User
A "common" query paging class that can query all tables in PHP

A "common" query paging class that can query all tables?
Recently, I wanted to write a page class that could be paged for all tables. Because in the actual development, I am afraid to query and display the result set paging is the most used code, and the structure of the table is diverse, I want to maximize the code reuse rate and maintainability.
Here is what I wrote, please give guidance, test, see if you can make better improvements and more support.
Currently, only a single table is supported, and federated queries are not supported. But the future can be considered how to support.?

Code:?

 C_error.= "is not connected to the database.           ";        Exit     } $this->c_result= $connection;        }//constructor, initialize variable function browser ($tablename, $row, $sql, $lation, erby) {$this->c_table= $tablename;        $this->c_rows= $row;        if (Empty ($this->c_offset)) {$this->c_offset=0;        if (empty ($tablename) or empty ($row) or empty ($sql)) {$this->c_error= "table without query or no batch shows how many rows or no query statements";        } $this->c_query= $sql;        if (!empty ($lation)) {$this->c_query.= "". $lation;        if (!empty (erby)) {$this->c_query.= "". erby; }}//Calculates the total number of pages function Tatolpage () {$sult =mysql_query ("SELECT count (*) as ' total_rows ' from $this->c_t        Able ", $this->c_result); if ($sult ==false) {$this->c_error.= "evaluates the total number of result sets for the purpose of query failure, please check.           ";        Exit        } $tempvar =mysql_fetch_array ($sult);     $this->total= $tempvar [0];  }//query to get result set, deposit in array c_found[][]   function Getfound () {$sult =mysql_query ($this->c_query, $this->c_result) or Die (Mysql_error ());        while ($found =mysql_fetch_array ($sult)) {$this->c_found[]= $found;        }}//Query the data and save the result paging to a variable function showtable () {$this->connect ();        $this->tatolpage ();        if (empty ($_get[offset])) {$_get[offset]=0;        } $this->c_query.= "Limit". $_get[offset]. ",". $this->c_rows;        $sult =mysql_query ($this->c_query, $this->c_result) or Die (Mysql_error ());        Parse query to get the field values to be displayed $tempvar =explode ("", $this->c_query);    $fields =explode (",", $tempvar [1]); field value (array)//display data to a table $echo _content.= "
 
  < td="">"; } $echo _content.= "
 
 
 
  
  "; while ([email Protected]_fetch_array ($sult)) {$echo _content.= "
  
  "; Displays the user-specified field, where you need to look closely for the for ($i =2; $i 
   "; }//Paging if ($this->c_rows==0) {$this->c_error.= "the number of pages per page cannot be 0"; Exit } $total _page=ceil ($this->total/$this->c_rows); $pre _page=$_get[offset]-$this->c_rows; Next $nex _page=$_get[offset]+ $this->c_rows; Display previous if ($pre _page>=0) {$echo _content.= " 
   "; }else{$echo _content.= "& Next Page"; } $echo _content.= " 
  
"; $echo _content.= "". $found [1]. "
on page & "; }else{$echo _content.= "
on page & "; }//Show page number for ($i =1; $i <= $total _page; $i + +) {if ($_get[offset]/$this->c_rows== ($i-1)) { $echo _content.= "&". $i. " Page & "; }else{$echo _content.= "&c_rows." > ". $i." & "; }}//Displays the next page if ($nex _page!=0 and ($_get[offset]+ $this->c_rows) <= $this->total) {$ec ho_content.= "& Next Page
"; return $echo _content; }}/* Example//browser ("table name", Number of displays per page, "SQL", "query Criteria", "sorting criteria"); $GGGG =new Browser ("News", 5, "Select Auto_id,news_title from News", "", "Order by newstime Desc"); $temp = $gggg->showtable (); Echo $temp; $GGGG->getfound () is the existence of a two-dimensional array of query result sets, which is not used in this example. */?>
?

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