在php分页中以连续方式显示记录数


Displaying number of records in continuous fashion in php paging

我有一个显示每页记录数量的页面。我在每页上显示5条记录,然后在下一页上显示5条记录,以此类推。寻呼工作很好,但问题是在第一页上,我显示数字串行明智旁边的每条记录,即从1到5。然后在下一页,它应该显示从6到10的数字,在下一页显示11到15,等等。但每一页的编号都是从1到5。我的代码如下。我试过不同的策略,但都不起作用。请检查代码,并告诉我在哪里进行更改,使其正常工作。提前谢谢你。

<div class="grid_12">
    <div class="box first round fullpage mh500 grid">
        <h2><?php echo $resource->_pageHead; ?></h2>
        <?php  $resource->displayMessage(); ?>
        <?php   
            if($resource->_recordCount > 0)
            {
        ?>
            <div class="block">
                <table class="listing" >
                    <thead>
                        <tr>
                            <th width="50" class="bdr-left">Sr. No.</th>
                            <th width="60">Name</th>
                            <th width="60">Email</th>
                            <th width="60">Address</th>
                            <th width="60">City</th>
                            <th width="60">State</th>
                            <th width="60">Phone Number</th>
                            <th width="60">Country</th>
                            <th width="60">Comment</th>
                            <th width="60">Inquiry Date</th>
                            <th width="60" class="bdr-right">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                        $i = 1;
                        $_SESSION['number'] = $i;
                        $perpage = 5;
                        $q = mysql_query("SELECT * FROM $resource->_table");
                        $total_record = mysql_num_rows($q);
                        $pages = ceil($total_record/$perpage);
                        $page = (isset($_GET['page']))?$_GET['page']:1;
                        $start = ($page-1) * $perpage;
                        $result = mysql_query("SELECT * FROM $resource->_table LIMIT $start, $perpage");
                        while($res = mysql_fetch_array($result))
                        {
                    ?>      
                            <tr class="odd gradeX">
                                <td><?php echo $i; ?></td>
                                <td><?php echo $res['name']; ?></td>
                                <td><?php echo $res['email'];?></td>
                                <td><?php echo $res['address'];?></td>
                                <td><?php echo $res['city'];?></td>
                                <td><?php echo $res['state'];?></td>
                                <td><?php echo $res['p_code']."-".$res['p_num'];?></td>
                                <td><?php echo $res['country'];?></td>
                                <td><?php echo substr($res['comments'], 0, 100);echo "...";?></td>
                                <td><?php echo $res['inquiry_date'];?></td>
                                <td align="center">
                                    <a href="<?php echo $_SERVER['PHP_SELF'].'?action=delete&id='.$res['id'];?>" onclick="return confirm('Do you want to delete this record?');">
                                        <img src="img/cross.png" alt="Delete" title="Delete"/>
                                    </a>
                                </td>
                            </tr>
                    <?php
                            $i++;
                        }
            }
                    ?>
                    </tbody>
                </table>
            </div>
            <div id="paging" style="padding-left:500px;">
                <?php
                    $prev=$page-1;
                    $next=$page+1;
                    if($prev > 0)
                    {
                        echo "<a href='?page=$prev'>Prev</a>";
                    }
                    echo "&nbsp;&nbsp;";
                    if($pages >= 1 AND $page <= $pages)
                    {
                        for($x=1;$x<=$pages;$x++)
                        {
                            echo "&nbsp;&nbsp;";
                            echo ($x==$page) ?"<a href=?page=$x style='"font-weight:normal;'">$x</a>":'<a href="?page='.$x.'" >'.$x.'</a>';
                        }
                        echo "&nbsp&nbsp";
                        if($page<$pages)
                        {
                            echo "<a href='?page=$next'>Next</a>";
                        }
                    }
                ?>
            </div>
    </div>
    <div class="clear"></div>
</div>

我希望下面的逻辑对你有帮助,初始化一个变量$i = 0;
通过以下逻辑

计算记录的起始编号
 $page_num   =   (int) (!isset($_GET['page']) ? 1 : $_GET['page']);
 $start_num =((($page_num*$num_records_per_page)-$num_records_per_page)+1);

初始化变量$i = 0;

然后在循环中计算序列号,如

$slNo = $i+$start_num;

然后回显$slNo;

代替echo $i;试试这个

$j= (($page-1) * $perpage) + i; echo $j;
You can go to this website and there is a simple example of pagination
http://snipplr.com/view/55519/ 
hope this works for you.