简体   繁体   English

在分页中为表格计数行?

[英]count row for table in pagination?

I have an problem with row num in following code.that means, in each page of pagination rows in table be counted from the beginning. 我在以下代码中遇到行num的问题。这意味着,在表的分页的每一页中,表的行都从头算起。 For example, the clear: 例如,清除:

P1: If we're on the first page of pagination, rows are the counts: P1:如果我们在分页的第一页,则行是计数:

1 Columns1
2 Columns2
3 Columns3
4 Columns4

P2: If we're on the first page of pagination, rows are the counts: P2:如果我们在分页的第一页,则行数为:

1 Columns1
2 Columns2
3 Columns3
4 Columns4

i need continue row count as 1234 5678 iam using this code 我需要使用此代码继续行计数为1234 5678 iam

$sql = mysql_query("select  *  from (two_make left join two_model on  two_make.make_id = two_model.make_id) left join two_variant on two_model.model_id = two_variant.model_id;");

$nr = mysql_num_rows($sql); 
if (isset($_GET['pn'])) { 
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']);  
} else { 
    $pn = 1;
} 
$itemsPerPage = 20; 
$lastPage = ceil($nr / $itemsPerPage);

if ($pn < 1) { 
    $pn = 1; 
} else if ($pn > $lastPage) { 
    $pn = $lastPage; 
} 

$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
}

$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 

$sql2 = mysql_query("select * from (two_make left join two_model on  two_make.make_id = two_model.make_id) left join two_variant on two_model.model_id = two_variant.model_id ORDER BY make ASC $limit"); 

$paginationDisplay = ""; 
if ($lastPage != "1"){

    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';

    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
    } 
     $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';

    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
    } 
}

$outputList = ''; ?>
<form name="form1" method="POST" action="">
<table width="578" border="1" align="center" id="menu">
<h3 style="color:#68ADD4;"><u>Two Wheeler List</u></h3>
    <tr>
    <th style="color:#68ADD4;">Si.no</th>
    <th style="color:#68ADD4;">Make</th>
    <th style="color:#68ADD4;">Model</th>
    <th style="color:#68ADD4;">Variant</th>
    <th style="color:#68ADD4;">Select</th>
       </tr>

<?php
$i=0;
 while($row=mysql_fetch_array($sql2))
 {
 $i++;
?>
<tr>
    <td><?php echo $i ;?></td>
    <td><?php echo $row['make'];?></td>
    <td><?php echo $row['model'];?></td>
    <td><?php echo $row['variant'];?></td>
    <td><center><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['variant_id'];?>"></center></td>
</tr>

<?php  } ?> 

Instead of echo $i; 代替echo $ i;

echo(($itemsPerPage * $pn) +$i); echo(($ itemsPerPage * $ pn)+ $ i);

Where $itemsPerpage is number of item per page and $pn is your page number 其中$ itemsPerpage是每页的项目数,$ pn是您的页码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM