我有一个包含最小值和最大值的价格范围,我想在其中
HTML 和 JS 方面:
<text>$</text><input type="number" id="from" name="fromPrice" readonly>
<text>$</text><input type="number" id="to" name="toPrice" readonly></p>
<div id="slider-range"></div>
</li>
<script>
$(function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 5000,
values: [ 300, 3000 ],
slide: function( event, ui ) {
$( "#from" ).val(ui.values[ 0 ]);
$( "#to" ).val( ui.values[ 1 ]);
document.getElementById("results").innerHTML = "<div class='loading-indication'><img src='ajax-loader.gif' /> Please wait... Loading New Courses...</div>";
var datastring = $('#testform').serialize(); // this will create key/value pairs to send to the phph page like `duration5=5` with a `&` separating each key/value pair
$('#display-datastring').html(datastring); // this line is just so you can see the variable being created
$.ajax({
url: 'fetch_pages.php',
type: 'post',
data: datastring,
success: function(res){
$('#results').html(res);
}
});
}
});
});
</script>
PHP 方面:
$fromPrice = isset($_POST['fromPrice']) ? $_POST['fromPrice']: null;
$toPrice = isset($_POST['toPrice']) ? $_POST['toPrice']: null;
然后...
$fromPriceArr = array();
if (!empty($fromPrice)) $fromPriceArr[] = $fromPrice;
if (count($fromPriceArr)>0) {
$get_crs_mysqli .= " AND (course_priceFinal <= ('".implode("','", $fromPriceArr)."')) ";
}
//To Price
$toPriceArr = array();
if (!empty($toPrice)) $toPriceArr[] = $toPrice;
if (count($toPriceArr)>0) {
$get_crs_mysqli .= " AND (cast(course_priceFinal = ('".implode("','", $toPriceArr)."')) ";
}
问题是我收到以下错误:
5023000 SELECT * FROM courses WHERE course_date1 >= CURRENT_DATE() AND (course_title like '%html%') SELECT * FROM courses WHERE course_date1 >= CURRENT_DATE() AND (course_title like '%html%') AND (course_priceFinal <= ('502')) AND (cast(course_priceFinal = ('3000')) ORDER BY course_date1 ASC LIMIT 0, 10 AND (course_priceFinal >= ('502')) AND (course_priceFinal <= ('3000'))
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\test\fetch_pages.php
1:您需要对查询失败的原因进行一些调查。无论您从查询中返回什么,都会返回错误,因此请进行一些简单的调试:
$res = mysqli_query($link, "SELECT * FROM `blah`");
if ( !$res ) {
printf("Errormessage: %s\n", mysqli_error($link));
exit;
}
2:这非常简单。只需在创建事件中手动添加值即可。 (仅当滑块移动时才会调用 Slide)。可以在此处找到工作示例。