HEX
Server: LiteSpeed
System: Linux s1321.sgp1.mysecurecloudhost.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: usas (2047)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /home/usas/swastikenterprises.usas.in/Admin/products.php
<?php
include 'include/header.php';

?>
<h1 class=" mt-4 mb-3">All Products</h1>
<div class="row">
  <div class="col-lg-6 col-md-6 col-sm-12"></div>
  <div class="col-lg-6 col-md-6 col-sm-12 text-right mb-3 cust-sheet">
  </div>
</div>
<?php
include 'Database/config.php';

$limit = 10;
if (isset($_GET['page'])) {
  $page = $_GET['page'];
  $serial = ($page - 1) * $limit + 1;
}else{
  $page = 1;
  $serial = 1;
}

$offset = ($page - 1) * $limit;

$sql = "SELECT 
          product_name.id AS pname_id,
          product_name.product_id,
          product_name.products_name,
          products.id AS prod_id,
          products.product_name
        FROM product_name
        LEFT JOIN products ON product_name.product_id = products.id
        ORDER BY product_id
        LIMIT {$offset}, {$limit}";
$serial = 1;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) >0) {
  

?>
<table class="table table-striped table-dark">
  <thead>
    <tr>
      <th scope="col" style="font-size:12px;">#</th>
      <th scope="col" style="font-size:12px;">Product Category Name</th>
      <th scope="col" style="font-size:12px;">Product Name</th>
      <th scope="col" style="font-size:12px;">Edit</th>
      <th scope="col" style="font-size:12px;">Delete</th>
      <th scope="col" style="font-size:12px;">Print</th>
    </tr>
  </thead>
  <tbody>
    <?php
    while ($row = mysqli_fetch_assoc($result)) {

    ?>
    <tr>
      <th  style="font-size:12px;"><?php echo $serial++;?></th>
      <td  style="font-size:12px;"><?php echo $row['product_name'];?></td>
      <td  style="font-size:12px;"><?php echo $row['products_name'];?></td>
      <td  style="font-size:12px;"><a href="edit-products.php?id=<?php echo $row['pname_id'];?>" style="color:#fff;"><i class="fa fa-edit"></i></a></td>
      <td  style="font-size:12px;"><a href="delete-products.php?id=<?php echo $row['pname_id'];?>" style="color:#fff;" onclick="return confirm('Are you sure you want to delete this record?');"><i class="fa fa-trash"></i></a></td>
      <td  style="font-size:12px;cursor:pointer;"><i class="fa fa-print" onclick="window.print()"></i></td>
    </tr>
    <?php       
    }
    ?>

  </tbody>
</table>

<?php } ?>

<!--Updated Code-->
<?php
$sql1 = "SELECT * FROM product_name";
$result1 = mysqli_query($conn, $sql1) or die('query failed');
if (mysqli_num_rows($result1) > 0) {
  $total_records = mysqli_num_rows($result1);
  
  $total_pages = ceil($total_records / $limit);
  echo '<ul class="pagination">';
  if ($page > 1) {
    echo '<li><a class="page-link" href="products.php?page='.($page - 1).'">Prev</a></li>';
  }
  for ($i=1; $i <=$total_pages ; $i++) { 
    if ($i == $page) {
      $active = "active";
    }else{
      $active = "";
    }
    echo '<li class="page-item '.$active.'"><a class="page-link" href="products.php?page='.$i.'">'.$i.'</a></li>';
  }
 if ($total_pages > $page) {
    echo '<li><a class="page-link" href="products.php?page='.($page + 1).'">Next</a></li>';
 }
  echo "</ul>";
}
?>

<!--Updated Code End-->

  <!--<ul class="pagination admin-pagination">
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
  </ul>-->

<?php
include 'include/footer.php';

?>