0
我收到了一个按价格从低到高排列产品的ajax脚本。这工作时,我没有动态页面,但现在数据根据页面别名(urlname)返回。在变量设置以外的脚本中使用变量(ajax)
所以下面的查询:
$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>
阿贾克斯:
$("#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] [ '身份证']必须认可。
$pid = $productcatcr[0]['id'];
<option value="lowhigh" data-post-url="prijslaaghoog.php?id='.$pid.'">Prijs: Laag naar hoog</option>
然后在我查询:
请告诉我$ productcactr? –
@Jonasw脚本需要加载的页面的ID。 – twan
您需要重构。我不能看到你的代码库,但它接到你发送ajax请求到不同的端点取决于下拉菜单。我在这4个php文件中对代码进行映像几乎完全一样,只是与sql不同的顺序。将请求发送到一个端点并且在发布数据中传递排序参数和页面参数会更有意义。 – Steve