企業(ユーザ)が商品をアップロードし、ブランド、色、素材などの仕様を挿入するウェブサイトがあります。
ビジターが目に見える製品を見つけたい場合、企業(ユーザー)がブランド、色、材質のように挿入する前にチェックボックスを選択できます。PHPフィルタリングmysqlマルチプレイチェックボックス
のチェックボックスのすべての結果が、今、私たちはここに問題を抱えているの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);
});
を示し、チェックボックスは、例えば、我々はモバイル用3チェックボックスを持って、不完全な仕事:
1.brands:サムスン、 LG、アップル
2.color:レッド、ブルー、グリーン
3.material:プラスチック、金属、ガラス
ビジターサムスンのチェックボックス(ブランド)をクリックし、レッド(色)は、結果を表示しなければならない場合赤いサムスンの。
しかし、私たちの主な問題は、結果を表示するにはチェックボックス(赤、メタル、サムスン)をすべてクリックする必要があることです。
訪問者がクリックした結果を表示するだけで、すべてのチェックボックスがいっぱいにならないようにします。
私たちのPHPコードはここにある:
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;}
最後に、我々は適切にamazon.comやebay.com我々はこの問題を解決するにはどうすればよい
のように働くのチェックボックスをオンにしたいですか?
This image is our product check boxes
感謝。
チェックボックスの組み合わせごとに生成するSQL文字列を比較しましたか?しかし、1,2 OR 3チェックボックスを選択できるようにすると、なぜ2つの条件しか扱われないのですか? 1つのチェックボックス、2つ以上のチェックボックスがあります。 –
http://codepen.io/desandro/pen/GFbAs – Strawberry
ブランド、色、材料などのすべてのチェックボックスでこの条件をどのように処理できるのですか? @Marc B –