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

Source: Internet
Author: User
In php, a "general" query page class that can be used to query all tables is a "general" query page class that can be used to query all tables? In a recent whim, I hope to write a paging class that can be used to query all tables. In actual development, I am afraid that the most frequently used code is to query and display the result set by page, while the table structure is diverse, I want to improve the code reuse rate and maintainability as much as possible .? I wrote the following: Please give me some advice to test a "common" query paging class in php that can query all tables.

What is the "general" query paging class that can be used to query all tables?
In a recent whim, I hope to write a paging class that can be used to query all tables. In actual development, I am afraid that the most frequently used code is to query and display the result set by page, while the table structure is diverse, I want to improve the code reuse rate and maintainability as much as possible .?
I wrote the following: could you give me some advice and test it to see if you can make better improvements and support .?
Currently, only a single table is supported, and joint query is not supported. But how can we support it in the future .?

Code :?

 C_error. = "no connection to the database. "; Exit ;}$ this-> c_result = $ connection;} // Constructor, initialization variable function browser ($ tablename, $ row, $ SQL, $ lation, $ orderby) {$ 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 = "no queried table or no batch display of many rows or no query statement";} $ this-> c_query = $ SQL; if (! Empty ($ lation) {$ this-> c_query. = "". $ lation;} if (! Empty ($ orderby) {$ this-> c_query. = "". $ orderby ;}// calculate the total number of pages function TatolPage () {$ sult = mysql_query ("select count (*) as 'total _ rows 'from $ this-> c_table ", $ this-> c_result); if ($ sult = false) {$ this-> c_error. = "query of the total number of computing result sets failed. Please check. "; Exit ;}$ tempvar = mysql_fetch_array ($ sult); $ this-> total = $ tempvar [0];} // query the result set, function GetFound () {$ sult = mysql_query ($ this-> c_query, $ this-> c_result) or die (mysql_error () saved in the array c_found ()); while ($ found = mysql_fetch_array ($ sult) {$ this-> c_found [] = $ found ;}// query data, and save the results 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 the query, get the field value to be displayed $ tempvar = explode ("", $ this-> c_query); $ fields = explode (",", $ tempvar [1]); // field value (array) // Display data to a table $ echo_content. ="
 
  
";}$ Echo_content. ="
 
 
 
  
  
"; While ($ found = @ mysql_fetch_array ($ sult) {$ echo_content. ="
  
  "; // Display the fields specified by the user. here you need to carefully read for ($ I = 2; $ I 
   ";}// Paging if ($ this-> c_rows = 0) {$ this-> c_error. = "The number of displayed pages cannot be 0"; exit;} $ total_page = ceil ($ this-> total/$ this-> c_rows ); $ pre_page = $ _ GET [offset]-$ this-> c_rows; // Next Page $ nex_page = $ _ GET [offset] + $ this-> c_rows; // display the previous page if ($ pre_page> = 0) {$ echo_content. =" 
   ";} Else {$ echo_content. =" & Next page";}$ Echo_content. =" 
  
"; $ Echo_content. =" ". $ found [1]."
Last page & ";} else {$ echo_content. ="
Previous Page & ";}// display 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. "&" ;}}// display the next page if ($ nex_page! = 0 and ($ _ GET [offset] + $ this-> c_rows) <= $ this-> total) {$ echo_content. = "& Next page
"; Return $ echo_content ;}}/* example // browser (" table name ", the number displayed on each page," SQL "," query condition ", "Sorting condition"); $ gggg = new browser ("news", 5, "select auto_id, news_title from news", "", "order by newstime desc "); $ temp = $ gggg-> ShowTable (); echo $ temp; // $ gggg-> GetFound () stores the query result set in a two-dimensional array, this example is not used. */?>
?

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.