Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying number of records in continuous manner in php paging

    I have a page which displays number of records on each page. I am displaying 5 records on each page and then next 5 on the next page and so on. Paging is working fine but the problem is on first page I'm displaying number serial wise next to each record i.e. from 1 to 5. Then on next page it should display numbers from 6 to 10 and on next page 11 to 15 and so on. But on every page numbers start from 1 to 5. My code is below. I have tried different strategies but nothing worked. Please check code and tell me where to make changes so that it works properly. Thanks a ton in advance.

    PHP Code:
    <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'], 0100);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 >= 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>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    its this line:

    PHP Code:

    for($x=1;$x<=$pages;$x++) 
    should be something like

    PHP Code:


    for($x=$start;$x<=$pages;$x++) 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •