Witam, mam taki problem, że jest sortowanie produktów po kategorii i cenie. Kategorie w pełni działają, za to kiedy wybiera się od najniższej lub od najwyższej ceny to nic się nie wyświetla. oto kod tej funkcji:
$_SESSION['category'] = $_POST['category'] == 'wszystko' ? null : $_POST['category'];
$sort_type = $_POST['filter'] == 'najwieksza' ? 'DESC' : 'ASC';
echo "<p>".$sort_type."</p>";
if(isset($_SESSION['category']))
{
$phpro_search_name = filter_var($_SESSION['product_search'], FILTER_SANITIZE_STRING);
$phpro_category = filter_var($_SESSION['category'], FILTER_SANITIZE_STRING);
$stmt = getDBH()->prepare("SELECT * FROM products WHERE name LIKE :search_name AND category=:category ORDER BY price $sort_type LIMIT $strona,8");
$stmt->bindValue(':search_name','%'.$phpro_search_name.'%');
$stmt->bindParam(':category', $phpro_category, PDO::PARAM_STR);
$stmt->execute();
}else{
$phpro_search_name = filter_var($_SESSION['product_search'], FILTER_SANITIZE_STRING);
$stmt = getDBH()->prepare("SELECT * FROM products WHERE name LIKE :search_name ORDER BY price $sort_type LIMIT $strona,8");
$stmt->bindValue(':search_name','%'.$phpro_search_name.'%');
$stmt->execute();
}
echo '<div class="text5">Wyniki wyszukiwania dla: '.$_SESSION['product_search'].'</div>';
while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo'
<div class="col-sm-6 col-md-3">
<input type="hidden" name="id" value="'.$r['id'].'">
<input type="hidden" name="price" value="'.$r['price'].'">
<input type="hidden" name="count" value="'.$r['name'].'">
<div class="thumbnail">
<img src="../graph/'.$r['picture'].'" alt="" class="img-responsive">
<div class="caption">
<h3 class="text-left">'.$r['name'].'</h3>
<p class="text-left">Cena: '.$r['price'].'zł</p>
<div class="btn-toolbar text-center">
<button type="submit" name="buy_product" class="btn btn-primary pull-right">Szczegoły</button>
</div>
</div>
</div>
</div>';
}
echo '</div>';
}