【问题标题】:Working with range slider and query使用范围滑块和查询
【发布时间】:2015-03-28 04:25:51
【问题描述】:

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

  1. 将其最小值和最大值与整数名称 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 `&` sepparating 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】:

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

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

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

    【讨论】:

    • 感谢您的回复。 2 我的滑块略有变化(不包括货币),我尝试添加初始值,但我认为它的幻灯片措辞不当:function(event, ui) { $( "#from" ).val(ui.values[ 0 ]) + '300'; $( "#to" ).val( ui.values[ 1 ]) + '3000';
    猜你喜欢
    • 2023-03-25
    • 2018-11-21
    • 2011-02-10
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多