У меня проблема с этим фильтром продукта. Проблема может быть с implode () или с IN ('{$platforma_filter}')
Каждый раз, когда он выводит только мои echo No Data Found
, но когда я удаляю это:
if(isset($_POST["platforma"]))
{
$platforma_filter = implode(',', $_POST["platforma"]);
$query .= "
AND id_platformy IN ('{$platforma_filter}')
";
}
if(isset($_POST["typ"]))
{
$typ_filter = implode(',', $_POST["typ"]);
$query .= "
AND id_typu IN('{$typ_filter}')
";
}
if(isset($_POST["zanr"]))
{
$zanr_filter = implode(',', $_POST["zanr"]);
$query .= "
AND id_zanr IN('{$zanr_filter}')
";
}
Тогда выводом являются все продукты.
if(isset($_POST["action"]))
{
$query = "
SELECT * FROM produkty WHERE
";
/*if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
{
$query .= "
AND cena BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
";
} */
if(isset($_POST["platforma"]))
{
$platforma_filter = implode(',', $_POST["platforma"]);
$query .= "
AND id_platformy IN ('{$platforma_filter}')
";
}
if(isset($_POST["typ"]))
{
$typ_filter = implode(',', $_POST["typ"]);
$query .= "
AND id_typu IN('{$typ_filter}')
";
}
if(isset($_POST["zanr"]))
{
$zanr_filter = implode(',', $_POST["zanr"]);
$query .= "
AND id_zanr IN('{$zanr_filter}')
";
}
<?php
$query = "SELECT DISTINCT(nazev_platformy),id_platformy FROM Platformy ORDER BY nazev_platformy DESC";
$statement = $conn->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="list-group-item checkbox">
<label><input type="checkbox" class="common_selector brand" value="<?php echo $row['id_platformy']; ?>" > <?php echo $row['nazev_platformy']; ?></label>
</div>
<?php
}
?>
</div>
</div>
<div class="list-group">
<h3>Typ Produktu</h3>
<?php
$query = "
SELECT DISTINCT(nazev_typu),id_typu FROM typ_produktu ORDER BY nazev_typu DESC
";
$statement = $conn->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="list-group-item checkbox">
<label><input type="checkbox" class="common_selector ram" value="<?php echo $row['id_typu']; ?>" > <?php echo $row['nazev_typu']; ?></label>
</div>
<?php
}
?>
</div>
<div class="list-group">
<h3>Žánr hry</h3>
<?php
$query = "
SELECT DISTINCT(nazev),id_zanr FROM zanr ORDER BY nazev DESC
";
$statement = $conn->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="list-group-item checkbox">
<label><input type="checkbox" class="common_selector storage" value="<?php echo $row['id_zanr']; ?>" > <?php echo $row['nazev']; ?></label>
</div>
<?php
}
?>
</div>
</div>
<div class="col-md-9">
<br />
<div class="row filter_data">
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
filter_data();
function filter_data()
{
$('.filter_data').html('<div id="loading" style="" ></div>');
var action = 'fetch_data';
var minimum_price = $('#hidden_minimum_price').val();
var maximum_price = $('#hidden_maximum_price').val();
var platforma = get_filter('platforma');
var typ = get_filter('typ');
var zanr = get_filter('zanr');
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{action:action, minimum_price:minimum_price, maximum_price:maximum_price, platforma:platforma, typ:typ, zanr:zanr},
success:function(data){
$('.filter_data').html(data);
}
});
}
function get_filter(class_name)
{
var filter = [];
$('.'+class_name+':checked').each(function(){
filter.push($(this).val());
});
return filter;
}
$('.common_selector').click(function(){
filter_data();
});
$('#price_range').slider({
range:true,
min:0,
max:65000,
values:[0, 65000],
step:50,
stop:function(event, ui)
{
$('#price_show').html(ui.values[0] + ' - ' + ui.values[1]);
$('#hidden_minimum_price').val(ui.values[0]);
$('#hidden_maximum_price').val(ui.values[1]);
filter_data();
}
});
});
</script>