<?php
require('top.inc.php');
require('connection.inc.php');


if(isset($_GET['type']) && $_GET['type']!=''){
	$type=get_safe_value($con,$_GET['type']);
	
	if($type=='delete'){
		$id=get_safe_value($con,$_GET['id']);
		$delete_sql="delete from product_post where id='$id'";
		mysqli_query($con,$delete_sql);
	}
}

?>
<div class="content pb-0">
	<div class="orders">
	   <div class="row">
		  <div class="col-xl-12">
			 <div class="card">
				<div class="card-body">
				   <h4 class="box-title text-center">Product List</h4>
				   <h4 class="box-link add-item" style="background: #2E86C1; padding: 12px 15px; border-radius: 5px; display: inline-block;">
				   		<a style="color: #fff; text-decoration: none;" href="manage_product.php">Add Product</a>
					</h4>
				</div>
				<div class="card-body--">
				   <div class="table-stats order-table ov-h">
					  <table class="table blog_table">
						 <thead>
							<tr>
							   <th>Serial</th>
							   <th>Name</th>
							   <th>Price</th>
							   <th>Image</th>
							   <th>Action</th>
							</tr>
						 </thead>
						 <tbody>
							<?php
						$sql = "SELECT * FROM product_post";
						$result = mysqli_query($con, $sql);
						$checkresult = mysqli_num_rows($result);

						if ($checkresult > 0) {
							while ($row = mysqli_fetch_assoc($result)) {
								$id = $row['id'];
								$serial++;
							?>
							
							<tr height="50">
							   <td class="serial"><?php echo $serial; ?></td>
							   
							   <td><?php echo $row['title']; ?></td>
							   <td><?php echo $row['price']; ?></td>
							   <td>
							       
							    <?php
							        echo "<div class='product-image'>";
							        echo "<img src='product_upload_image/".$row['image']."'>";
							        echo "</div>";
							      ?>
							
							</td>
							   <td>
							       <?php
								echo "<span class='badge badge-edit'><a href='product_update.php?id=".$row['id']."'>Edit</a></span>&nbsp;";
								
								echo "<span class='badge badge-delete'><a href='?type=delete&id=".$row['id']."'>Delete</a></span>";
								
								?>
							   </td>
							</tr>
							<?php
					}
						}
					?>
						 </tbody>
					  </table>
				   </div>
				</div>
			 </div>
		  </div>
	   </div>
	</div>
</div>
<?php
require('footer.inc.php');
?>