Euro 2024 sweepstakes!
Prizes to be won this summer! Click here to take part, and find yourself a team to cheer on!
Show your pride!
Rainbows galore in our forum shop, including snazzy colours for your username and even a rainbow-coloured... football?
Join Habbox!
Be part of the Habbox family - there are so many roles to pick from! Click here to get your application rolling


Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    51
    Tokens
    313

    Default Pagination! PHP MYSQL RESULTS

    Hello guys!

    I'm currently in the middle of a project and to finalize this i have to add a pagination into my MYSQL results..

    I seriously have tried what i could think of and obviously it's just not enough! I'd love it if someone could
    kindly fix this code so that the results would show only show 25 lines then ask for page 2 etc etc.

    The code is:
    (ignore my messy coding)
    PHP Code:
    <?php


        
    require("header.php");


    // Retrieve data from database
    $sql='SELECT * FROM repairdata ORDER BY id DESC';
    $result=mysql_query($sql);
        
        
    ?>
    /// STYLE & HTML CODE ////

    <?php
                                    
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr class='odd gradeX'>
                                        <td width='64'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['id']; ?></font></td>
                                        <td width='90'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Status']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustName']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh1']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustInvoiceNumber']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh2']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Product']; ?></font></td>
                                    </tr><?php
    // close while loop
    ?>    

    /// MORE HTML CODE ////

    <?php
    // close MySQL connection
    mysql_close();
    ?>
    Currently when i load the page it's showing all of my records in this database which is just over 1,000 lines. (Not Kidding)

    I'm quite desperate at the moment! I'll do anything for a quick response that will fix this!

    Thank you,
    Chris
    Last edited by Foxcom; 10-02-2013 at 11:12 AM.

  2. #2
    Join Date
    Oct 2012
    Location
    Nottingham
    Posts
    85
    Tokens
    473
    Habbo
    FlyingPigs!

    Default

    Something like this: (haven't tested)

    PHP Code:
    <?php
                                    
    $limit 
    15;
    $page = (isset($_GET["page"])) ? (int) $_GET["page"] : 1;

    $start = ($page 1) * $limit;
    $result "YOUR QUERY HERE";
    $row mysql_num_rows($result);
    $pages  ceil($row $limit);
    $counter 1;

    while(
    $counter <= $pages){
        echo 
    "<a href=\"page_name.php?page=$counter\">$counter</a>";
    $counter++;
    }

    $result2 mysql_query("YOUR QUERY HERE BUT WITH: LIMIT $start$limit");
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result2)){
    ?>
    <tr class='odd gradeX'>
                                        <td width='64'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['id']; ?></font></td>
                                        <td width='90'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Status']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustName']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh1']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustInvoiceNumber']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh2']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Product']; ?></font></td>
                                    </tr><?php
    // close while loop
    ?>    

    /// MORE HTML CODE ////

    <?php
    // close MySQL connection
    mysql_close();
    ?>
    I haven't done this for a while so it may not work.

  3. #3
    Join Date
    Nov 2012
    Posts
    51
    Tokens
    313

    Default

    Thank you for your input!

    I have had this issue resolved by Matt,
    If someone could close this it'd be great!

    Thank you once again!


    Quote Originally Posted by FlyingPigs View Post
    Something like this: (haven't tested)

    PHP Code:
    <?php
                                    
    $limit 
    15;
    $page = (isset($_GET["page"])) ? (int) $_GET["page"] : 1;

    $start = ($page 1) * $limit;
    $result "YOUR QUERY HERE";
    $row mysql_num_rows($result);
    $pages  ceil($row $limit);
    $counter 1;

    while(
    $counter <= $pages){
        echo 
    "<a href=\"page_name.php?page=$counter\">$counter</a>";
    $counter++;
    }

    $result2 mysql_query("YOUR QUERY HERE BUT WITH: LIMIT $start$limit");
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result2)){
    ?>
    <tr class='odd gradeX'>
                                        <td width='64'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['id']; ?></font></td>
                                        <td width='90'><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Status']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustName']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh1']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustInvoiceNumber']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['CustPh2']; ?></font></td>
                                        <td><font size='1'><a href="booking.php?id=<? echo $rows['id']; ?>"><? echo $rows['Product']; ?></font></td>
                                    </tr><?php
    // close while loop
    ?>    

    /// MORE HTML CODE ////

    <?php
    // close MySQL connection
    mysql_close();
    ?>
    I haven't done this for a while so it may not work.

Posting Permissions

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