Hello! I need a search with filter relative to the page of product by category, that is, when searching for products by a certain category show in the sidebar filter options like: new or used, minimum price up to maximum price, etc. for better understanding see the image:
Assuming the category is CARS, the siderbar would look like this:
Belowisthecode,butIamalaymanandIdonotknowhowtocallthevalueofthecheckboxchosenandthepricefield.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT condição FROM carros WHERE condição=$_POST['cond']";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Aqui aparece os carros com a condição escolhida na checkbox;
}
} else {
echo "Nada foi encontrado.";
}
$sql = "SELECT preço FROM carros WHERE condição > $_POST['ps'] AND condição < $_POST['pe']";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Aqui aparece os carros com o intervalo de preço determinado;
}
} else {
echo "Nada foi encontrado.";
}
mysqli_close($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script><title></title></head><body><divclass="page_listing">
<div class="grid-row">
<div class="grid-col col-1">
<aside class="site_sidebar">
<div id="searchmain" class="section_search">
<div class="section_search-by-category">
<div class="search-category" id="search-category">
<h4 class="search-category-title">Filtros</h4>
<div class="section_subcategory-filter">
<div class="category-nav">
</div>
<div class="search-subcategory-filter cat_9020"">
<div id="searchextras" class="subcategory-filters">
<a href="#gofilters" id="gofilters"></a>
<div id="condition" class="condition featurebox filter checklist">
<p class="term">Novo/Usado</p>
<ul class="list">
<li class="item">
<label class="form-label" for="produto_novo">
<input class="form-field form-field-checkbox" type="checkbox" name="cond[]" title="Novo" id="condition_1" value="1" >
Novo
</label>
</li>
<li class="item">
<label class="form-label" for="produto_usado">
<input class="form-field form-field-checkbox" type="checkbox" name="cond[]" title="Usado" id="condition_2" value="2" >
Usado
</label>
</li>
</ul>
</div>
<div id="pricerange" class="pricerange featurebox filter range">
<label class="term" for="ps">Preço</label>
<input class="form-field form-field-text half" type="text" name="p_min" id="ps" placeholder="Mín." maxlength="13" value="a" >
<input class="form-field form-field-text half" type="text" name="p_max" id="pe" placeholder="Máx." maxlength="13" value="b" >
<input type="submit" class="btn btn-green btn-filter btn-disabled" value="Filtrar" id="price_bt">
</div>
</div>
</div>
</div>
</div>
</body>
</html>