在分页中计算表格的行数?

时间:2022-10-06 15:30:20

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. 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  } ?> 

1 个解决方案

#1


1  

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是您的页码

#1


1  

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是您的页码