Mono_Pic Trust & Quality
English     Urdu

Customer address detail PHP MySQL with pagination Part 03

Friends here is 3rd  part. Here we will go ahead and make files for Pagination of list file.

Pagination  is a proves to devide webpage data in pages, its easy to load and show pages.  We change our list.php as below. Page numbers will show at last.

     < ?php

    include ('menue.php');     

    if(isset($_GET['updatestatus'])) {

    echo  $delstatus =$_GET['updatestatus'];

    }

    ?>

     < center>

     < ?php include "db.php";

    $results_per_page = 10;

    $sql='SELECT * FROM customers';

    $result = mysqli_query($conn, $sql);

    $number_of_results = mysqli_num_rows($result);

    $number_of_pages = ceil($number_of_results/$results_per_page);

    if (!isset($_GET['page'])) {

      $page = 1;

    } else {

      $page = $_GET['page'];

    }

   $this_page_first_result = ($page-1)*$results_per_page;

     ?>

     < h2>Customer Contact List < /h2>

        < table border="1" cellpadding="8">

     < tr> < th>ID < /th> < th>Name < /th> < th>Phone < /th> < th>Email < /th> < th>Address < /th> < th>Date < /th> < th>Edit < /th> < th>Delete < /th> < /tr>

     < ?php

    $sql='SELECT * FROM customers LIMIT ' . $this_page_first_result . ',' .  $results_per_page;

    $result = mysqli_query($conn, $sql);

    while($row = $result->fetch_assoc()){

     ?>

       < tr>

                  < td>  < ?php echo $row['id']; ?>  < /td>

                 < td>  < ?php echo $row['name']; ?>  < /td>

                 < td>  < ?php echo $row['phone']; ?>  < /td>

                 < td>  < ?php echo $row['email']; ?>  < /td>

                 < td>  < ?php echo $row['address']; ?>  < /td>

                 < td>  < ?php echo $row['created_at']; ?>  < /td>

             < td> < a href="edit_list.php?editid= < ?php echo $row['id'];?>"> Edit < /td>      

         < td> < a href="delete.php?delid= < ?php echo $row['id'];?>"> Delete < /td>

           < /td>

       < /tr>

       < ?php     

    }

   ?>

     < /table>

     < br /> < br /> < br /> < br />

 < div style="position: relative; background-color: #969696; border: 0px solid blue; width:200px; height:30px"> 

  < ?php

for ($page=1;$page < =$number_of_pages;$page++) {

  echo ' < a href="list.php?page=' . $page . '">' . $page. '  ' . ' < /a> ';

}

echo '

     < /div> ' ; 

  include ('footer.php');      

    ?>

   < /center>