/home/hdwebsolution/www/ns-interior/admin-pages/update-sub-category.php
<?php include('site-header.php'); ?>
<!-- end of LOGO CONTAINER -->
<!-- - - - - - - - - - - - - -->
<!-- start of SIDEBAR -->
<!-- - - - - - - - - - - - - -->
<?php include('left-nevigation.php'); ?>
<!-- - - - - - - - - - - - - -->
<!-- end of SIDEBAR -->
<!-- - - - - - - - - - - - - -->
<main id="playground">
<!-- - - - - - - - - - - - - -->
<!-- start of TOP NAVIGATION -->
<!-- - - - - - - - - - - - - -->
<?php include('site-top-header.php'); ?>
<?php
if(isset($_GET['del']) && $_GET['del']!=='')
{
$del_id = $_GET['del'];
$sql_del = "DELETE p, sc FROM `tbl_sub_category` sc
LEFT JOIN `tbl_product` p ON p.`pro_sub_category` = sc.`id`
WHERE sc.id = '$del_id'";
$run = mysqli_query($link,$sql_del);
if($run==true)
{
echo "<script>alert('Category delected..!'); window.location.href='update-sub-category.php';</script>";
}
}
if(isset($_POST['Add_header_status'])) {
$add_hid = $_POST['sub_id'];
$query = "SELECT * FROM `tbl_sub_category` WHERE `header_status` = 1";
$result = mysqli_query($link, $query);
$count = mysqli_num_rows($result);
if($count >= 2) {
$msg = "<p style='color:red;'>Sub category only 2 in header allowed!</p>";
} else {
$add_updateQuery = "UPDATE `tbl_sub_category` SET `header_status`=1 WHERE `id`='$add_hid'";
if(mysqli_query($link, $add_updateQuery)) {
$msg = "<p style='color:green;'>Sub category added to the header!</p>";
} else {
$msg = "<p style='color:red;'>Error updating header status: " . mysqli_error($link) . "</p>";
}
}
}
// Remove_header_status
if(isset($_POST['Remove_header_status'])) {
$remove_hid = $_POST['sub_id'];
$remove_updateQuery = "UPDATE `tbl_sub_category` SET `header_status`=0 WHERE `id`='$remove_hid'";
if(mysqli_query($link, $remove_updateQuery)) {
$msg = "<p style='color:green;'>Sub category removed from the header</p>";
} else {
$msg = "<p style='color:red;'>Error updating header status: " . mysqli_error($link) . "</p>";
}
}
//Footer
if(isset($_POST['Add_footer_status'])) {
// print_r($_POST);
// die();
$add_hid = $_POST['sub_id'];
$query = "SELECT * FROM `tbl_sub_category` WHERE `footer_status` = 1";
$result = mysqli_query($link, $query);
$count = mysqli_num_rows($result);
if($count >= 12) {
$msg = "<p style='color:red;'>Sub category only 12 in footer allowed!</p>";
} else {
$add_updateQuery = "UPDATE `tbl_sub_category` SET `footer_status`=1 WHERE `id`='$add_hid'";
if(mysqli_query($link, $add_updateQuery)) {
$msg = "<p style='color:green;'>Sub category added to the footer!</p>";
} else {
$msg = "<p style='color:red;'>Error updating footer status: " . mysqli_error($link) . "</p>";
}
}
}
// Remove_header_status
if(isset($_POST['Remove_footer_status'])) {
$remove_hid = $_POST['sub_id'];
$remove_updateQuery = "UPDATE `tbl_sub_category` SET `footer_status`=0 WHERE `id`='$remove_hid'";
if(mysqli_query($link, $remove_updateQuery)) {
$msg = "<p style='color:green;'>Sub category removed from the footer</p>";
} else {
$msg = "<p style='color:red;'>Error updating footer status: " . mysqli_error($link) . "</p>";
}
}
?>
<section id="page-title" class="row">
<div class="col-md-8">
<h1>Sub Category</h1>
<p class="lead">Update your product Sub category below</strong>.</p>
</div>
<div class="col-md-4" style="text-align:end">
<a href="add-edit-sub-category.php" class="btn btn-primary"> + Sub Category</a>
</div>
<div><?=@$msg;?></div>
</section>
<!-- / PAGE TITLE -->
<div class="container-fluid">
<!-- / row -->
<div class="row">
<div class="col-md-12">
<section class="panel panel-primary">
<header class="panel-heading">
<h3 class="panel-title">Existing Sub Categories</h3>
</header>
<table class="table table-hover table-responsive" width="100%">
<tbody>
<tr>
<th scope="row" style="color:black;">S. No</th>
<th style="color:black;">Name</th>
<!--<th style="color:black;">Category Name</th>-->
<th style="color:black;">Action</th>
</tr>
<?php
$sn=0;
$sql_cate = "SELECT
cs.category_id,
CASE
WHEN cs.category_id = 0 THEN 'Independent Category'
ELSE c.cate_name
END AS cate_name,
cs.* FROM tbl_sub_category AS cs
LEFT JOIN tbl_category AS c ON c.cat_id = cs.category_id";
$sel = mysqli_query($link,$sql_cate);
while($arr = mysqli_fetch_assoc($sel))
{
$sn++;
?>
<tr>
<td><?=$sn?></td>
<td><?=$arr['name']?></td>
<!-- <td><img src="../category-image/<?=$arr['image'];?>" alt="<?=$arr['image'];?>" height="100px" width="100px"></td> -->
<td><a class="btn btn-success" href="add-edit-sub-category.php?edit=<?=$arr['id'];?>">Edit</a>
<a class="btn btn-danger" href="?del=<?=$arr['id'];?>">Delete</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</section>
</div>
</div>
</div>
<!-- / container-fluid -->
<?php include('site-footer.php'); ?>