我有多个产品类别,因此根据我点击的页面,我希望能够将WHERE pc.item_category_id = 3
更改为pc.item_category_id = $cat_value
。
test.php的
<div id="get_product" class="form-row">
// <?php $cat_value = 3; ?> does not work, error in sql
</div>
action.php的
if(isset($_POST["getProduct"])){
$product_query = "SELECT * FROM product_items as pi
INNER JOIN product_category as pc ON pi.item_category = pc.item_category
WHERE pc.item_category = 3 // need to be able to change that to a variable like $cat_value
ORDER BY pi.product_item_id LIMIT $start, $limit";
$result = $conn->query($product_query);
etc...
//WHERE pc.item_category = 3 to WHERE pc.item_category = $cat_value does not work
}
test.js
function product(){
$.ajax({
url : "action.php",
method: "POST",
data : {getProduct:1},
success : function(data){
$("#get_product").html(data);
}
})
}