We have a website that corporations(Users) upload their products, and they insert specifications like brand,color,material.
when visitors want to find sightly product they can choose the check boxes that corporations(Users) before inserted like brand,color,material.
All results of check boxes show with Ajax
function getEmployeeFilterOptions() {
var opts = [];
$checkboxes.each(function () {
if (this.checked) {
opts.push(this.value);
}
});
return opts;
}
function updateEmployees(opts) {
$.ajax({
type: "POST",
url: "ajax/filterProducts.php",
data: {
filterOpts: opts, catIDp2:<?php echo $_GET['catIDp']; ?>
},
success: function (records) {
$('#response').html(records);
}
})
;
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function () {
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
Now we have a problem here , The check boxes work incomplete , For example we have 3 check box for mobile:
1.brands: Samsung,LG,Apple
2.color: Red,Blue,Green
3.material: Plastic,Metal,Glass
If visitor click on check box of Samsung(Brand) and Red(Color) must be show the result of red Samsungs.
But our main problem is visitor have to click on all of check boxes( Red,Metal,Samsung) to show results.
So we want just show results that visitor click on it, no all of check boxes filled.
our php code is here:
function getFilterProducts($cat, $filter = null){
global $db;
$result = '';
$sql = '';
if (count($filter) == 1) {
if ($filter != null) {
$val = implode("','", $filter);
$sql = "SELECT productID_C,subCatID_Product,title_Product_C,status,url_seo_product,priceStatus_C,priceProduct_C,backgroundUrlPrd_C,create_date_product,priceProduct_C,countryProductFarsi_C,brandNameFarsi_Product_C,companyID,genreProductFarsi_C,colorProductFarsi_C
FROM $db->products_company WHERE (countryProductFarsi_C IN ('$val') AND subCatID_Product='$cat') OR (brandNameFarsi_Product_C IN ('$val') AND subCatID_Product='$cat') OR (companyID IN ('$val') AND subCatID_Product='$cat') OR (genreProductFarsi_C IN ('$val') AND subCatID_Product='$cat') OR (colorProductFarsi_C IN ('$val') AND subCatID_Product='$cat') ORDER BY create_date_product DESC";
$result = $db->query($sql);
}
} elseif (count($filter) >= 2) {
if ($filter != null) {
$val = implode("','", $filter);
$sql = "SELECT productID_C,subCatID_Product,title_Product_C,status,url_seo_product,priceStatus_C,priceProduct_C,backgroundUrlPrd_C,create_date_product,priceProduct_C,countryProductFarsi_C,brandNameFarsi_Product_C,companyID,genreProductFarsi_C,colorProductFarsi_C
FROM $db->products_company WHERE subCatID_Product='$cat' AND countryProductFarsi_C IN ('$val') AND brandNameFarsi_Product_C IN ('$val') AND companyID IN ('$val') AND genreProductFarsi_C IN ('$val') AND (colorProductFarsi_C IN ('$val')) ORDER BY create_date_product DESC";
$result = $db->query($sql);
}
} else {
$sql = "SELECT productID_C,subCatID_Product,title_Product_C,status,url_seo_product,priceStatus_C,priceProduct_C,backgroundUrlPrd_C,create_date_product,priceProduct_C,countryProductFarsi_C
FROM $db->products_company WHERE subCatID_Product='$cat' ORDER BY create_date_product DESC";
$result = $db->query($sql);
}
if ($result) {
$listFilterPrd = $result->fetch_all(MYSQLI_ASSOC);
return $listFilterPrd;
}
return null;}
Finally we want check boxes works properly like amazon.com or ebay.com
How we can fix this problem?
This image is our product check boxes
Thanks.
Aucun commentaire:
Enregistrer un commentaire