I got an ajax script which sorts products by price from lowest to high. This worked when I didn't have dynamic pages, but now data is returned according to the page alias (urlname).
我有一个ajax脚本,按价格从最低到高排序产品。这在我没有动态页面时有效,但现在根据页面别名(urlname)返回数据。
So the following query:
所以以下查询:
$product = "SELECT * FROM `snm_content`
WHERE `catid` = 15 AND state = 1 order by introtext ASC";
Needs to be:
需要是:
$produc = "SELECT * FROM `snm_content`
WHERE `catid` = '".$conn->real_escape_string($productcatcr[0]['id'])."'
AND state = 1 order by introtext ASC";
But the problem is, the other file doesn't recognize $conn->real_escape_string($productcatcr[0]['id'])
because it is used on another page.
但问题是,另一个文件无法识别$ conn-> real_escape_string($ productcatcr [0] ['id']),因为它在另一个页面上使用。
Do I need to post it and then get it or something?
我需要发布它然后得到它或什么?
Here the correct script is loaded depending what option is selected:
这里根据选择的选项加载正确的脚本:
<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 is where $productcatcr[0]['id'] needs to be recognized.
prijslaaghoog.php是需要识别$ productcatcr [0] ['id']的地方。
1 个解决方案
#1
0
I fixed it by posting the variable through the url like so:
我通过url发布变量来修复它,如下所示:
$pid = $productcatcr[0]['id'];
<option value="lowhigh" data-post-url="prijslaaghoog.php?id='.$pid.'">Prijs: Laag naar hoog</option>
And then in my query:
然后在我的查询中:
$product = "SELECT * FROM `web_content` WHERE `catid` = '".$_GET['id']."' AND state = 1 order by introtext ASC";
#1
0
I fixed it by posting the variable through the url like so:
我通过url发布变量来修复它,如下所示:
$pid = $productcatcr[0]['id'];
<option value="lowhigh" data-post-url="prijslaaghoog.php?id='.$pid.'">Prijs: Laag naar hoog</option>
And then in my query:
然后在我的查询中:
$product = "SELECT * FROM `web_content` WHERE `catid` = '".$_GET['id']."' AND state = 1 order by introtext ASC";