Processing Method for complex data retrieval and paging display

Source: Internet
Author: User

System title: processing method for complex data retrieval and pagination
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 '<Table width = "100%" border = "0"> ';
Print '<tr class = "text"> <TD width = "50%"> <Div align = "center"> ';
If ($ offset <> 1) {// If the offset is 0, the link to the previous page is not displayed.
$ Newoffset = $ offset-1;
Print "<a href = '$ php_self? Offset = $ newoffset '> previous page </a> ";
} Else {
Print "Previous Page ";
Print "";
}
// Display all pages
For ($ I = 1; $ I <= $ pages; $ I ++ ){
$ Temps = "<a href = '". $ php_self .'? Offset = '. $ I. "'>". $ I. "</a> ";
Print $ temps;
Print "";
}
// Check whether it is the last page
If ($ pages! = 0 & $ offset! = $ Pages ){
$ Newoffset = $ Offset + 1;
Print "<a href = '$ php_self? Offset = $ newoffset '> next page </a> ";
} Else print "next page ";
Print '</div> </TD> ';
Print '<TD width = "50%"> <Div align = "center"> ';
Print "Current page:". $ offset. "Total". $ pages. "Page ";
Print '</div> </TD> ';
Print "</table> ";

// Display query information
Print '<Table width = "100%" border = "1"> ';
Print '<tr class = "text"> ';
Print '<TD width = "100%"> <Div align = "center"> query result information </div> </TD> ';
Print '</tr> ';

$ 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 )) {
// display the information content by means of interlace display
if ($ li_number = 0) {

$ li_number = 1;
}else {

$ li_number = 0;
}< br> $ tempstr = " ". $ row ['lk _ title']. "";
Print ' '. $ tempstr. '';
Print '';
}< br> Print "";
?>
----------------------------
welcome to zhangcg.oso.com.cn

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.