使用范围滑块和查询 - 如何操作?

问题描述 投票:0回答:1

我有一个包含最小值和最大值的价格范围,我想在其中

  1. 将其最小值和最大值与 int 名称 course_priceFinal 进行比较 发生的事情很简单,在用户使用价格范围选择最低和最高价格后,它会使用 ajax 发布,然后我进行比较。

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' /> &nbsp; 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. 显示其初始值,开始时不会显示任何值,直到您点击滑块 http://jsfiddle.net/b453V/52/
javascript php jquery mysql mysqli
1个回答
0
投票

1:您需要对查询失败的原因进行一些调查。无论您从查询中返回什么,都会返回错误,因此请进行一些简单的调试:

$res = mysqli_query($link, "SELECT * FROM `blah`");
if ( !$res ) {
    printf("Errormessage: %s\n", mysqli_error($link));
    exit;
}

2:这非常简单。只需在创建事件中手动添加值即可。 (仅当滑块移动时才会调用 Slide)。可以在此处找到工作示例。

© www.soinside.com 2019 - 2024. All rights reserved.