Browse Source

Filtrage funciona + ordenacio

master
janmaroto 3 weeks ago
parent
commit
74f3285dbd
  1. 61
      form.php
  2. 12
      home.php
  3. 35
      my-products.php

61
form.php

@ -1,9 +1,8 @@
<form name="filter" method="POST" action="home.php">
<div class="w3-container-padding">
<div class="w3-third">
<div class="w3-container w3-cell-row">
<div class="w3-container w3-cell w3-mobile">
<input class="w3-input w3-border" type="text" placeholder="Search by name or description.." id="search" name="search">
</div>
<div class="w3-third">
<div class="w3-container w3-cell w3-mobile">
<select class="w3-select w3-border" id="category" name="category">
<option value="empty" selected>Category</option>
<option value="1">Wooden</option>
@ -13,28 +12,34 @@
<option value="5">Aluminium</option>
</select>
</div>
<div class="w3-third">
<div class="w3-row w3-border">
<select class="w3-select w3-half" id="minPrice" name="minPrice">
<option value="empty" selected>Min Price</option>
<option value="0">0</option>
<option value="15000">15.000</option>
<option value="70000">70.000</option>
<option value="200000">200.000</option>
<option value="1000000">1.000.000</option>
</select>
<select class="w3-select w3-border w3-half" id="maxPrice" name="maxPrice">
<option value="empty" selected>Max Price</option>
<option value="15000">15.000</option>
<option value="70000">70.000</option>
<option value="200000">200.000</option>
<option value="1000000">1.000.000</option>
<option value="2000000">2.000.000</option>
</select>
</div>
<div class="w3-container w3-border w3-cell w3-mobile">
<select class="w3-select" id="minPrice" name="minPrice">
<option value="empty" selected>Min Price</option>
<option value="0">0</option>
<option value="15000">15.000</option>
<option value="70000">70.000</option>
<option value="200000">200.000</option>
<option value="1000000">1.000.000</option>
</select>
</div>
<div class="w3-container w3-border w3-cell w3-mobile">
<select class="w3-select" id="maxPrice" name="maxPrice">
<option value="empty" selected>Max Price</option>
<option value="15000">15.000</option>
<option value="70000">70.000</option>
<option value="200000">200.000</option>
<option value="1000000">1.000.000</option>
<option value="2000000">2.000.000</option>
</select>
</div>
<div class="w3-container w3-cell w3-mobile">
<select class="w3-select w3-border" id="order" name="order">
<option value="asc" selected>Order</option>
<option value="asc">Asc</option>
<option value="desc">Desc</option>
</select>
</div>
<!-- <input type="text" id="lname" name="lname"> -->
<input class="w3-bar-item w3-button" type="submit" value="Submit">
</div>
</form>
<div class="w3-container w3-cell w3-mobile">
<input class="w3-button" type="submit" value="Submit">
</div>
</div>

12
home.php

@ -17,7 +17,9 @@ include_once('parameters.php');
</div>
<?php
echo('<form name="filter" method="POST" action="home.php">');
include_once('form.php');
echo('</form>');
?>
<div class="w3-bar w3-margin"></div>
@ -34,22 +36,18 @@ include_once('parameters.php');
$productCategory = $_POST['category'];
$minProductPrice = $_POST['minPrice'];
$maxProductPrice = $_POST['maxPrice'];
// echo ($productName . $productInfo . $productCategory . $minProductPrice . $maxProductPrice);
$productOrder = $_POST['order'];
$sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products WHERE 22=22";
if (!empty($_POST['search'])) $sqlString .= " AND (bp_product_name LIKE '$productName' OR bp_product_info LIKE '$productInfo')";
if (!empty($_POST['search'])) $sqlString .= " AND (bp_product_name LIKE '%$productName%' OR bp_product_info LIKE '%$productInfo%')";
if ($productCategory != "empty") $sqlString .= " AND bp_product_category = $productCategory";
if ($minProductPrice != "empty") $sqlString .= " AND bp_product_price >= $minProductPrice";
if ($maxProductPrice != "empty") $sqlString .= " AND bp_product_price <= $maxProductPrice";
echo $sqlString;
if ($productOrder != "asc") $sqlString .= " ORDER BY bp_product_name DESC";
$sql = $con->prepare($sqlString);
// $sql->bind_param("ssidd", $productName, $productInfo, $productCategory, $minProductPrice, $maxProductPrice);
} else {
$sql = $con->prepare("SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products");

35
my-products.php

@ -36,7 +36,9 @@ $username = $_SESSION['username'];
</div>
<?php
echo('<form name="filter" method="POST" action="my-products.php">');
include_once('form.php');
echo('</form>');
?>
<div class="w3-bar w3-margin"></div>
@ -48,28 +50,23 @@ $username = $_SESSION['username'];
if (!empty($_POST)) {
$productName = isset($_POST['search']) ? "%" . $_POST['search'] . "%" : "%%";
$productInfo = isset($_POST['search']) ? "%" . $_POST['search'] . "%" : "%%";
$productCategory = ($_POST['category'] != "empty") ? $_POST['category'] : "%";
$minProductPrice = ($_POST['minPrice'] != "empty") ? $_POST['minPrice'] : 0;
$maxProductPrice = ($_POST['maxPrice'] != "empty") ? $_POST['maxPrice'] : 999999999999999999;
echo ($productName . $productInfo . $productCategory . $minProductPrice . $maxProductPrice);
$sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products";
$sqlString .= " WHERE (bp_product_name LIKE ? OR bp_product_info LIKE ?)";
$sqlString .= " AND bp_product_category = ?";
$sqlString .= " AND (bp_product_price >= ? AND bp_product_price <= ?);";
$sql = $con->prepare($sqlString);
$sql->bind_param("ssidd", $productName, $productInfo, $productCategory, $minProductPrice, $maxProductPrice);
$productName = $_POST['search'];
$productInfo = $_POST['search'];
$productCategory = $_POST['category'];
$minProductPrice = $_POST['minPrice'];
$maxProductPrice = $_POST['maxPrice'];
$sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products WHERE bp_product_owner = $userid";
if (!empty($_POST['search'])) $sqlString .= " AND (bp_product_name LIKE '%$productName%' OR bp_product_info LIKE '%$productInfo%')";
if ($productCategory != "empty") $sqlString .= " AND bp_product_category = $productCategory";
if ($minProductPrice != "empty") $sqlString .= " AND bp_product_price >= $minProductPrice";
if ($maxProductPrice != "empty") $sqlString .= " AND bp_product_price <= $maxProductPrice";
$sql = $con->prepare($sqlString);
} else {
$sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products WHERE bp_product_owner = ?";
$sql = $con->prepare($sqlString);
$sql->bind_param("i", $userid);
$sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products WHERE bp_product_owner = $userid";
$sql = $con->prepare($sqlString);
}
$sql->execute();

Loading…
Cancel
Save