Excuse me: Paging problems

Source: Internet
Author: User
Ask: Questions about paging! Hello everyone, I am a newbie. I made a PHP page, and the basic effect has been achieved. I want to make the color of the current page different from that of other pages. how can I achieve this? I thought about it for several days! In addition, if my page number is too large, how can I hide the page number? How can I center the current page ??? Thank you! & Lt ;? Php & nbsp; for details, refer to the paging questions!
Hello everyone, I am a newbie. I made a PHP page, and the basic effect has been achieved. I want to make the color of the current page different from that of other pages. how can I achieve this? I thought about it for several days! In addition, if my page number is too large, how can I hide the page number? How can I center the current page ??? Thank you!

Received ("conn. php"); // connect to the database
// Pagination
$ Pagesize = 10; // set the number of entries displayed on one page

$ Qw = mysql_query ("select count (*) from 'blog '");
$ We = mysql_fetch_array ($ qw );
$ Er = $ we [0]; // returns the total number of database tables.

$ Pages = intval ($ er/$ pagesize); // get the page number
If ($ er % $ pagesize ){
$ Pages ++;
}

// Set the current page
If (isset ($ _ GET ['Page']) {
$ Page = intval ($ _ GET ['Page']);
} Else {
$ Page = 1;
}

$ Offset = $ pagesize * ($ page-1); // calculates the start number
$ SQL = "select * from 'blog 'order by id desc limit $ offset, $ pagesize ";
$ Query = mysql_query ($ SQL );

While ($ rs = mysql_fetch_array ($ query )){


?>
">


...


"> Read the full text>



}
?>

// Display the page
$ Shouye = 1;
$ Shangye = $ page-1;
$ Xiaye = $ page + 1;
$ Weiye = $ pages;
If ($ page> 1 ){
Echo "Page 1 ";
Echo "previous page ";
}
// Number of cyclic pages
For ($ I = 1; $ I <= $ pages; $ I ++ ){
Echo "". $ I ."";
}

If ($ page <$ pages ){
Echo "next page ";
Echo "last page ";
}
?>

------ Solution --------------------
Good, hoho

Major changes here

// Number of cyclic pages
For ($ I = 1; $ I <= $ pages; $ I ++ ){
Echo "". $ I ."";
}

This loop starts with $ I from max ($ page-X, 1) and ends with min ($ page + X, $ pages). If the page number is sufficient, 2 * X + 1 indicates the total number of pages displayed (excluding the front, back, first, and last pages]

$ I ===$ page, indicating the current page
------ Solution --------------------
PHP code
/*** Set the paging style ** @ access public * @ param integer $ showNumCount to display several numbers (for example, 1 2 3 ...) * @ param integer $ total page number of totalPage data * @ param integer $ current page number ** @ return array $ pageNumList page number (number) list */function showNumber ($ showNumCount, $ totalPage, $ page) {$ showNumCount = $ totalPage >=$ showNumCount? $ ShowNumCount: $ totalPage; if ($ totalPage> $ showNumCount & $ page> ceil ($ showNumCount/2 )) {if ($ totalPage-$ page> floor ($ showNumCount/2) {$ pageNumList = array_slice (range (1, $ totalPage ), $ page-floor ($ showNumCount/2)-1, $ showNumCount);} else {$ pageNumList = range ($ totalPage-$ showNumCount + 1, $ totalPage-$ showNumCount + $ showNumCount); }} else {$ showNumCount = $ showNumCount? $ ShowNumCount: 1; $ pageNumList = range (1, $ showNumCount);} return $ pageNumList;} $ showNumCount = 10; // Display ten pages $ totalPage = 100; // assume that there are a total of 100 page data $ currentPage = 9; // if the selected page is 9th $ pageNumList = showNumber ($ showNumCount, $ totalPage, $ currentPage ); /* next you only need to output the page numbers cyclically in html and add connections. of course, if the current page is identified, you can do something like this: {foreach from = $ pageNumList item = page} {$ page} {/foreach }*/

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.