我有一个ajax脚本,按价格从最低到高排序产品。这在我没有动态页面时有效,但现在根据页面别名(urlname)返回数据。
以下查询:
$product = "SELECT * FROM `snm_content`
WHERE `catid` = 15 AND state = 1 order by introtext ASC";
需要:
$produc = "SELECT * FROM `snm_content`
WHERE `catid` = '".$conn->real_escape_string($productcatcr[0]['id'])."'
AND state = 1 order by introtext ASC";
但问题是,另一个文件无法识别$conn->real_escape_string($productcatcr[0]['id'])
,因为它在另一个页面上使用。
我需要发布它然后得到它还是什么?
根据选择的选项加载正确的脚本:
<div class="form-group">
<label class="grey" for="orderby">Sorteer op:</label>
<select class="form-control orderby" name="orderby" id="orderby">
<option value="default" data-post-url="default.php">Standaard</option>
<option value="popularity" data-post-url="populairst.php">Meest bekeken</option>
<option value="highlow" data-post-url="prijshooglaag.php">Prijs: Hoog naar laag</option>
<option value="lowhigh" data-post-url="prijslaaghoog.php">Prijs: Laag naar hoog</option>
</select>
</div>
的Ajax:
$("#orderby").on('change', function() {
var option = $('#orderby > option').filter(':selected');
$.post("ajax/" + option.data("post-url"), {
filter: option.val()
}, function(result){
$("#productviewajax").html(result);
});
});
prijslaaghoog.php需要识别$ productcatcr [0] ['id']。
答案 0 :(得分:0)
我通过网址发布变量来修复它,如下所示:
$pid = $productcatcr[0]['id'];
<option value="lowhigh" data-post-url="prijslaaghoog.php?id='.$pid.'">Prijs: Laag naar hoog</option>
然后在我的查询中:
$product = "SELECT * FROM `web_content` WHERE `catid` = '".$_GET['id']."' AND state = 1 order by introtext ASC";