PHP+mysql database query paging code example
Release: 2016-07-25 08:52:14
Original
1176 people have browsed it
-
-
/* - * php+mysql paging code
- *
- */
$SQL_TABL="abc"; //table name
- $where_name="id > 10";//Query conditions
- $perpagenum = 3; //Number displayed per page
$total = mysql_fetch_array(mysql_query("select count(*) AS count from $SQL_TABL WHERE (".@$where_name.")"));
- $sql_count=$total['count']; //Get the number of returned data
- unset($total); //Unregister the variable $total
//Calculate the inaccurate number of pages $page_all_num_f is an integer, $page_all_num_t is an accurate value (may be a decimal)
- $page_all_num_f=round($page_all_num_t=$sql_count/$perpagenum, 0);
- if($page_all_num_f<$page_all_num_t) //Calculate the correct number of pages
- $page_all_num=$page_all_num_f+1;
- else
- $page_all_num=$page_all_num_f;
if( is_numeric(@$_GET['p']) && @$_GET['p']>1 && @$_GET['p']<=$page_all_num) //Get the GET parameters to determine the current page
- $page_num= $_GET['p'];
- else
- $page_num=1;
$sql_s_num=($page_num-1)*$perpagenum; //Calculate the starting number of data items
- $sql_p ="LIMIT ".$sql_s_num." , ".$perpagenum; //Generate database query code
- $result = mysql_query("select * from $SQL_TABL WHERE (".@$where_name.") ".$sql_p); / /Query data
while($row=mysql_fetch_array($result)){ //Main loop
- //Output content
- }
//Page button
- for($i=1;$i<=$page_all_num;$i++)
- {
if(@$_GET[name]!=null) //Other GET parameters of the page
- $p_n="name=".@$_GET[name]."&";
- else
- $p_n=null;
if($page_num==$i) //Current page Number emphasis
- $p_flag="class="flag" ";
- else
- $p_flag=null;
echo "$in";
- }
- ?>
-
Copy code
Recommended reading:
- php and ajax no refresh paging code
- php article paging implementation code
- php limit page turning (pagination) code
- PHP paging class with multiple paging methods
- PHP pagination code for previous page and next page
- PHP paging code for the first ten pages and the next ten pages
- Example of simple php pagination code
- A good php pagination code
- A paging function: Previous page Next page
- A useful php paging class
- php long article pagination code
- A practical php paging class
- Fast php paging class
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31