Complex data retrieval and display by page. System Title: complex data retrieval and display by page processing method system function: use a temporary table to retrieve database data, and then display by page: processing method: Use a temporary table to store the system Title: processing method for complex data retrieval and paging display
System Function: you can use a temporary table to retrieve database data and display it by page:
Solution: Use a temporary table to store the intermediate data results and display the data according to the intermediate results.
Data Display adopts the line-by-line method
Processing advantages: for complex queries, especially data queries involving multiple tables, if the query conditions are directly used
The overhead will be very high. use a temporary table to save and process the data first. In this way, only one query of the database is required.
Usage: you only need to change the user information and data table connecting to the database.
// Connect to the database
$ Dbh = mysql_connect ('localhost: 100', 'root ','');
Mysql_select_db ('test ');
// Save the data retrieval result to the temporary table
$ Ls_ SQL = 'create temporary table temps ';
$ Ls_ SQL. = 'SELECT lk_title, lk_link from lk_t_content ';
$ Ls_ SQL. = "where lk_title like '%". $ searchcontent. "% '";
$ Res = mysql_query ($ ls_ SQL, $ dbh );
// Obtain the total number of retrieved data
$ Ls_ SQL = 'SELECT count (*) as rcnt_con from temps ';
$ Res = mysql_query ($ ls_ SQL, $ dbh );
$ Rcon = $ row ["rcnt_con"];
$ Pages = ceil ($ rcon/20); // The total number of pages for the $ pages variable
If (empty ($ offset )){
$ Offset = 1;
$ Curline = 0;
} Else
$ Curline = ($ offset-1) * 20;
// Print the header
Print'
';Print'
| '; If ($ offset <> 1) {// if the offset is 0, the link to the previous page is not displayed. $ Newoffset = $ offset-1; Print "previous page "; } Else { Print "previous page "; Print ""; } // Display all pages For ($ I = 1; $ I <= $ pages; $ I ++ ){ $ Temps = "". $ I .""; Print $ temps; Print ""; } // Check whether it is the last page If ($ pages! = 0 & $ offset! = $ Pages ){ $ Newoffset = $ offset + 1; Print "next page "; } Else print "next page "; Print' | ';Print'
'; Print "current page:". $ offset. "total". $ pages. "page "; Print' | ';Print"
";
// Display query information
Print'
';Print'
';Print'
| Query result information | ';Print'
';$ Query = "select lk_title, lk_link from temps order by lk_title desc LIMIT". $ curline. ", 20 ";$ Res = mysql_query ($ query, $ dbh );$ Li_num = 0;While ($ row = mysql_fetch_array ($ res )){// The information is displayed in the form of a line-by-line display.If ($ li_number = 0 ){
$ Li_number = 1;} Else {
$ Li_number = 0;}$ Tempstr = "". $ row ['LK _ title']. "";Print'
| '. $ Tempstr .' | ';Print'
';}Print"
";
?>
----------------------------
Welcome to zhangcg.oso.com.cn
System Function: use a temporary table to retrieve database data and display it by page. Solution: Use a temporary table for storage...