Using Filter option to get products by their sizes.
This is the product database structure:
id | size
------------
1 | S,M
2 | S,M,L
3 | S
4 | M,L
This is the Shirtsize database structure:
id | size
------------
1 | S
2 | M
3 | L
This is the code of input value get for filter
<div class="list-group">
<h3>Size</h3>
<?php
$query = "SELECT DISTINCT(shirtsize) FROM shirtsize ORDER BY id DESC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="list-group-item checkbox">
<label>
<input type="checkbox" class="common_selector size" value="<?php echo $row['shirtsize']; ?>">
<?php echo $row['shirtsize']; ?>
</label>
</div>
<?php
}
?>
</div>
This code to get the values from database:
if(isset($_POST["size"]))
{
$size_filter = implode("','", $_POST["size"]);
if (is_array($size_filter))
{
foreach ($size_filter as $value)
{
$query .= "AND size like('%".$value."%')";
}
}
else{
$query .= "AND size like('%".$size_filter."%')";
}
}
In here i have database like s,m,l like this and post data also look like this s,m i tried this way to get values but the result is null.. I am not good in english so if any inconvinient sorry for that guys.