I have this code in fliters.php:
<div class="boxed1 mb-3">
<h5 class="text-center" style="padding-top: 15px;">Categories</h5>
<hr>
<?php if(substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1) == "all-products.php"){ ?>
<h6 style="margin-left: 10px;">All Products</h6>
<?php }else{ ?>
<h6 style="margin-left: 10px;"><a href="all-products">All Products</a></h6>
<?php }
$sql1 = $db->prepare("SELECT * FROM categories WHERE id IN (SELECT parent FROM categories) AND parent = ? AND deleted = ?");
$sql1->bind_param('ii', $var0, $var0);
$sql1->execute();
$result1 = $sql1->get_result();
while($row1 = mysqli_fetch_assoc($result1)){
?>
<h6 style="margin-left: 10px;"><a href="main-category?cat=<?=$row1['id'];?>"><?=$row1['category'];?></a></h6>
<?php
$sql2 = $db->prepare("SELECT * FROM categories WHERE parent IN (SELECT id FROM categories) AND parent = ? AND deleted = ?");
$sql2->bind_param('ii', $row1['id'], $var0);
$sql2->execute();
$result2 = $sql2->get_result();
while($row2 = mysqli_fetch_assoc($result2)){ ?>
<h6 style="margin-left: 25px;"><a href="sub-category?cat=<?=$row2['id'];?>"><?=$row2['category'];?></a></h6>
<?php }
}
$sql3 = $db->prepare("SELECT categories.*
FROM categories
INNER JOIN
products
WHERE categories.id
NOT IN (SELECT categories.parent FROM categories)
AND categories.parent = ?
AND categories.deleted = ?
AND products.category = categories.id");
$sql3->bind_param('ii', $var0, $var0);
$sql3->execute();
$result3 = $sql3->get_result();
while($row3 = mysqli_fetch_assoc($result3)){
?>
<h6 style="margin-left: 10px;"><a href="sub-category?cat=<?=$row3['id'];?>"><?=$row3['category'];?></a></h6>
<?php } ?>
</div>
and this code in main-category.php:
<?php
require_once 'init.php';
include 'includes/head.php';
include 'includes/navigation.php';
$arr = array();
$sql = $db->prepare("SELECT * FROM categories WHERE parent = ? AND deleted = ?");
$sql->bind_param('ii', $_GET['cat'], $var0);
$sql->execute();
$result = $sql->get_result();
while($row = mysqli_fetch_assoc($result)){
$arr[] = $row['id'];
}
$test = implode(",", $arr);
$array = array_map('intval', explode(',', $test));
$array = implode("','", $array);
$query = $db->query("SELECT * FROM products WHERE category IN ('$array') AND archived = 0 ORDER BY name");
?>
<!-- Main Content -->
<div class="container-fluid" style="margin-top:45px;">
<div class="row">
<div class="col-lg-2">
<?php include 'includes/filters.php'; ?>
</div>
<div class="col-lg-1"></div>
<div class="col-lg-8">
<?php
$catSql = $db->prepare("SELECT * FROM categories WHERE id = ?");
$catSql->bind_param('i', $_GET['cat']);
$catSql->execute();
$result7 = $catSql->get_result();
$childs = mysqli_fetch_assoc($result7);
$pSql = $db->prepare("SELECT * FROM categories WHERE id = ?");
$pSql->bind_param('i', $childs['parent']);
$pSql->execute();
$result20 = $pSql->get_result();
$parents = mysqli_fetch_assoc($result20);
?>
<h6 id="backcolor2">
<nav>
<ol class="breadcrumb justify-content-center">
<li class="breadcrumb-item"><a href="index">Home</a></li>
<li class="breadcrumb-item"><a href="all-products">Products</a></li>
<li class="breadcrumb-item"><?=$childs['category'];?></li>
</ol>
</nav>
</h6>
<br>
<div class="row row-cols-1 row-cols-md-4 g-4">
<?php while($row2 = mysqli_fetch_assoc($query)) : ?>
<div class="col d-flex align-items-stretch">
<div class="card">
<img src="<?=explode('/', $_SERVER['PHP_SELF'])[1].'/'.$row2['image'];?>" class="card-img-top">
<div class="card-body text-center">
<h6 class="card-title mb-3"><?=$row2['name'];?></h6>
<a href="products?details=<?=$row2['id'];?>" class="btn btn-sm btn-success button_hover stretched-link">Details</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
Now the main categories are listed in the filters
<h6 style="margin-left: 10px;"><a href="main-category?cat=<?=$row1['id'];?>"><?=$row1['category'];?></a></h6>
and when I press on one of them the url will appear like this:
https://test.com/main-category?cat=72
I need to change the url to appear like this example:
https://test.com/hair-care-categories
What I have tried:
How can I do this? What should I edit in the code above?