PHP php after page change, the problem of serial number
$MYSQL->query ("Select Cu.*,cy.name from Customer cu,custtype cy where 1=1 and Cu.code=cy.code limit 0,18");
for ($i =1; $i < $count; $i + +) {
$MYSQL->fetch ($i);
$customerid = $MYSQL->data[customerid]; Customer number
$KSName = $MYSQL->data[ksname]; User name-abbreviation
echo "$i"; Serial number
echo "$customerid"; Customer number
echo "$KSName"; User name-abbreviation
?>
I am every 18 records for a page, the first serial number is from 1-18, but I switch to the 2nd page, the serial number is from 1 to 18th, the same as the 3rd page, probably because I paged, I tried, if there is no problem, but here I can not page, Please do not have a good way to solve this problem.
Reply to discussion (solution)
Limit 0,18
Your limit here is the first one that's always been 0, of course it's the result.
Limit 0,18 here should be the paging parameter passed through.
for ($i =1; $i < $count; $i + +) {
echo "$i"; Serial number
Your serial number is generated by the program, of course, starting from 1.
Upstairs reply This is to resolve the issue of the content of the page after the change
Unable to resolve issue with serial number start again
I mean, how to fix me. After the page is changed, the sequence number starts with the last ordinal of the first page, such as 1-18, and the second page ordinal is starting from 19. Instead of starting from 1.
Everyone said is the cause of the cause, the reason I know, upstairs brothers, did not say the solution.
Set the desired page number to be passed in by $_get[' page '), there is
$offs = * Isset ($_get[' page ')? $_get[' Page '-1:0; $MYSQL->query ("Select Cu.*,cy.name from Customer cu,custtype cy where 1=1 and Cu.code=cy.code Lim it $offs); for ($i = $offs +1; $i < $offs + $count; $i + +) {$MYSQL->fetch ($i); $customerid = $MYSQL->data[ CustomerID]; Customer Ref. $ksname= $MYSQL->data[ksname]; User name-echo "$i";//serial number echo "$customerid"; Customer number echo "$KSName"; User name-abbreviation
Reply to the 6 floor of the brothers, as if still not,
I think the moderator method is possible, first try to put your page number into the $offs, followed by the 6# to write on it.
Set variables separately, calculate ordinal numbers
function Toolkit_pages ($page, $total, $phpfile, $pagesize = 3, $pagelen = 3, $link = "&") {$num _t_count = $total; $phpf ile = "index.php?". $phpfile; $pagecode = "; Defining variables, storing html$page = Intval ($page) for paging generation; Avoid non-numeric page $total = Intval ($total); Ensure that the total record value type is correct if (! $total) return array (); The total number of records is zero returns an empty array $pages = Ceil ($total/$pagesize); Calculate Totals page//Handle page number legality if ($page < 1) $page = 1;if ($page > $pages) $page = $pages;//calculate query Offset $offset = $pagesize * ($page-1) ;//page range calculation $init = 1; Starting page number $max = $pages; End page Number $pagelen = ($pagelen% 2)? $pagelen: $pagelen + 1; Number of pages $pageoffset = ($pagelen-1)/2; Page number offset//generate Html$pagecode = ''. $total. ""; $pagecode. ="$page/$pages"; page, a few pages//if the first page, then the first page and the previous page of the connection if ($page! = 1) {$pagecode. = "<<"; First page $pagecode. = "Prev"; Previous page}//can offset if ($pages > $pagelen) {//If the current page is less than or equal to the left offset if ($page <= $pageoffset) {$init = 1; $max = $pagelen;} E LSE {//If the current page is greater than the left offset//If the current page number is offset beyond the maximum pagination if ($page + $pageoffset >= $pages + 1) {$init = $pages-$pagelen + 1;} else {//left/right bias The calculation $init = $page-$pageoffset; $max = $page + $pageoffset;}}} Generate htmlfor ($i = $init; $i <= $max; $i + +) {if ($i = = $page) {$pagecode. = ''. $i. '';} else {$pagecode. = "$i";}} if ($page! = $pages) {$pagecode. = "Next"; Next page $pagecode. = ">>"; Last page} $pagecode. = '; return array (' pagecode ' = $pagecode, ' sqllimit ' = ' limit '. $offset. ',' . $pagesize);} Reference description/* Page List */if (url_get (' count_page ') '! = ') {$count _page = url_get (' Count_page ');} else {$count _page = 15;} if (url_get (' page ') <= 0 | | url_get (' page ') = = ') {$page = 1;} else {$page = url_get (' page ');} $t _count = $this->cmspage_model->row_array ();//Count the number of records write your own SQL statement $t_first = ($page-1) * $count _page; $list = $this-& Gt Cmspage_model->result_array ($t _first, $count _page);//Returns an array itself write an SQL statement//reference paging function $getpageinfo = Toolkit_pages ($page, $ T_count, "C=page&m=index", $count _page, 8);
#10 Lou Brothers wrote like a paging code, with my question, it seems that the relationship is not big.
Seek the Great God, and solve ... .........
Seek the Great God, and solve ... .........
The 6 floor has been solved for you, you are still begging, you can not ask someone to help you write the complete code. Focus on the use of the limit of the SQL statement. How do you get more than 800 of your technology? Are you here to amuse us?
#14, brother, if you don't know the question, don't be ridiculous. Ok!!!!!!!!!!
#14, brother, if you don't know the question, don't be ridiculous. Ok!!!!!!!!!!
When you change the page number, it should be to get the URL of the incoming $page value, such as $_get[' page ';
Then, every time you page, there is a $page_size, your $page_size=18;
So, when you display on the page, the ID number of that list should be: ($page-1) * $page _size+ $i; The $i value is the subscript of the array.
$page =$_get[' page ']; $page _size=18; $count = $MYSQL->query ("SELECT count (*) from Customer Cu,custtype Cy where 1=1 and Cu.code=cy.code "), $pages = Ceil ($count/$page _size), if ($page <1) $page = 1;if ($page > $pages) $page = $pages; $offset = ($page-1) * $page _size;if ($offset <0) $offset = 0; $MYSQL->query ("Select Cu.*,cy.name from Customer cu,custtype Cy W Here 1=1 and Cu.code=cy.code limit ". $offset.", ". $page _size); for ($i =1; $i < $count; $i + +) {$MYSQL->fetch ($i); $customerid = $MYSQL->data[' customerid '); Customer number $ksname= $MYSQL->data[' ksname ']; User name-abbreviation $thispage= ($page-1). $page _size+ $i; echo ". $thisPage." ";//serial number echo" $customerid "; Customer number echo "$KSName"; User name-abbreviation}
I don't know $mysql the specifics of this object, so the other place is a train of thought, focusing on
$thisPage = ($page-1). $page _size+ $i;
This sentence.
Correction, unexpectedly cannot edit, should be: $thisPage = ($page-1) * $page _size+ $i;
Well, #16 Lou Brothers are right. Thank you so much.