How to create pagination automatically using php/mysql?

Hi
I want to know how can i create pagination directly from database using php/mysql am try to create it but am stack right now because it only show ten rows but it doesn’t break any page, here are my pages
sold.php

<?php include 'header.php';?>
<?php include ('../control/function.php'); ?>
<!--MENU SECTION END-->
    <div class="content-wrapper">
         <div class="container">
        <div class="row pad-botm">
            <div class="col-md-12">
                <h4 class="header-line">Background For Sold Items</h4>
                
                            </div>

        </div>
             <div class="row " style="padding-bottom:40px;">
           <div class="container-fluid">
            <table>
              <th>NO:</th>
              <th>SOLD ITEMS</th>
              <th>DATE</th>
              <?php view_sold(); ?>
            </table>
</div>

</div>
</div>
                   <!-- COMMENT SECTION - ONE END-->
    </ul>
                
                   </div>
             </div>
             </div>
        </div>
    <!-- CONTENT-WRAPPER SECTION END-->
   <?php include 'footer.php';?>

function.php

function view_sold(){
  include ('connect.php');
  $select_admin_details="select * from new LIMIT 0,10";
  $run_admin_details=mysql_query($select_admin_details);

  while ($row_data=mysql_fetch_array($run_admin_details)) {

    $aid=$row_data['id'];
    $sold=$row_data['solditem'];
    $date=$row_data['date'];
    
    echo "<tr>
        <td>$aid</td>
        <td>$sold</td>
        <td>$date</td>
        </tr>";
      }
}

Your query retrieves the first ten rows from your table. What you need to do now is to put a link for the “next page” which calls the same function, but recovers the next ten rows. One way would be to pass the page number, or the starting row, into the view_sold() function and have your link or Ajax call provide it. Once you have that, obviously you can add links to previous page, first page, and so on.

You also need to look at moving from the old-style (and no longer part of the language) mysql calls and use something like mysqli or, my preference, PDO.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.