How to implement query and paging together

Source: Internet
Author: User
How to implement query and paging together? at last, this post was edited by u014474944 from 2014-04-0420: 14: 27: Query & nbsp; and & nbsp; on pages; just don't know how to combine the two together & nbsp; the code is as follows $ pageisset ($ _ GET [page])? $ _ GET [page]: 1; & nbsp how to implement query and paging together

This post was last edited by u014474944 at 20:14:27 on

Both query and paging can be implemented, but I don't know how to combine them.
The code is as follows:

$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
$sql="SELECT count(*) from khxx";
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";

if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ;
$wh="where {$ww}";
}





Echo "homepage ";
Echo "previous page ";
Echo "next page ";
Echo "last page ";
?>


 
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>


------ Solution --------------------
How can we integrate it?
SQL queries the content of the current page. That is to say, you only need to display the content queried on the current page and compile the page number.
------ Solution --------------------

$ Page = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
$ Pagesize = 20;

If (! Empty ($ _ GET [keys]) {
$ Keys = $ _ GET ['Keys '];
$ Ww = "'dates' like '%". $ keys. "%' or 'area' like '%". $ keys. "% '";
$ Wh = "where {$ ww }";
} Else {
$ Wh = ""
}

$ SQL = "SELECT count (*) from khxx". $ wh; // add search criteria when calculating the total number
$ Res = mysql_query ($ SQL );
$ Maxrows = mysql_result ($ res, 0, 0 );
$ Maxpages = ceil ($ maxrows/$ pagesize );
If ($ page> $ maxpages ){
$ Page = $ maxpages ;}
If ($ page <1 ){
$ Page = 1 ;}
$ Limit = "limit". ($ page-1) * $ pagesize). ", {$ pagesize }";

// Query records on the current page
$ SQL = "SELECT * FROM 'khxx' {$ wh} order by id desc {$ limit }";
$ Query = mysql_query ($ SQL );
While ($ rs = mysql_fetch_array ($ query )){

?>

------ Solution --------------------
You have to write the search field into the URL and pass the parameter.
------ Solution --------------------
No query conditions are attached to your paging entries.
------ Solution --------------------
Reference:
Quote: reference:

You have to write the search field into the URL and pass the parameter.

I just don't know how to write it. no idea.


Echo "previous page ";

You can add this query field to the paging URL.
------ Solution --------------------
Reference:
Quote: reference:


$ Page = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
$ Pagesize = 20;

If (! Empty ($ _ GET [keys]) {
$ Keys = $ _ GET ['Keys '];
$ Ww = "'dates' like '%". $ keys. "%' or 'area' like '%". $ keys. "% '";
$ Wh = "where {$ ww }";
} Else {
$ Wh = ""
}

$ SQL = "SELECT count (*) from khxx". $ wh; // add search criteria when calculating the total number
$ Res = mysql_query ($ SQL );
$ Maxrows = mysql_result ($ res, 0, 0 );
$ Maxpages = ceil ($ maxrows/$ pagesize );
If ($ page> $ maxpages ){
$ Page = $ maxpages ;}
If ($ page <1 ){
$ Page = 1 ;}
$ Limit = "limit". ($ page-1) * $ pagesize). ", {$ pagesize }";

// Query records on the current page
$ SQL = "SELECT * FROM 'khxx' {$ wh} order by id desc {$ limit }";
$ Query = mysql_query ($ SQL );
While ($ rs = mysql_fetch_array ($ query )){

?>

The effect is similar to what I wrote.
I wrote a question: after clicking the next page, the current query status disappears. I want to ask how to write the query to the page.


Then you need to add the condition parameter to the flip-through url. for example, the next page needs to be written like this.
Echo "next page ";

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.