使用范围滑块和查询

时间:2015-03-28 04:25:52

标签: javascript php jquery mysql mysqli

我有一个最小值和最大值的价格范围,我想

  1. 将其最小值和最大值与int名称course_priceFinal进行比较 简单来说,在用户使用价格范围选择最低和最高价格后,它会使用ajax发布然后我进行比较。
  2. 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/

1 个答案:

答案 0 :(得分:0)

1:您需要对该查询失败的原因进行一些调查。无论你从查询返回什么,都会返回一个错误,所以做一些简单的调试:

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

2:那太简单了。只需在create事件中手动添加值即可。 (仅在移动滑块时调用滑动)。可以找到工作样本here