使用PHP获取价格范围的价值

时间:2015-01-15 16:48:34

标签: javascript php jquery mysql slider

我正在使用类似的价格范围: http://jsfiddle.net/dhana36/b453V/2/

我希望能够使用PHP从以下javascript函数中获取价格范围内的最小值和最大值的值:

 $(function() {
    $( "#slider-range" ).slider({
      range: true,
      min: 0,
      max: 2000,
      values: [ 300, 1000 ],
      slide: function( event, ui ) {
        $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
      }
    });
    $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
      " - $" + $( "#slider-range" ).slider( "values", 1 ) );
  });

以下是我要实现的目标:

$p1 = value from minimum value;
$p2 = value from maximum value;
$get_crs = mysql_query("SELECT * FROM products where product_price BETWEEN '$p1' AND '$p2' ORDER BY product_date1");

因此,我的问题如下: 我有一个滑块,搜索结果按最低和最高价格动态过滤,我的问题是如何填写以下空白:

   $p1 = blank;
    $p2 = blank;

注意: 如果你对它的html部分感到好奇,下面就是代码:

  <label for="amount" id="Price">Price Range</label><br>
  <input type="text" id="amount">
</p>
<div id="slider-range"></div>

如果您需要任何澄清,请告诉我。

1 个答案:

答案 0 :(得分:0)

//bul.php or other send methots...
<?
if($_POST)
{
    $_POST['amount'];
    $values = str_replace(' ','',$_POST['amount']);
    $values = str_replace('$','',$values);
    $values = explode('-',$values);
    $min = $values[0];
    $max = $values[1];
  
    $HTML='';
};
echo $min;
echo $max;
?>

//html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Başlıksız Belge</title>
  <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
  
  
  
  
  <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
  
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">
  
    
      <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script>
$(function() {
    $('select').change(function(){
     $( "#amount" ).val( $('select').val() + $( "#slider-range" ).slider( "values", 0 ) +
      " - "+ $('select').val() + $( "#slider-range" ).slider( "values", 1 ) );
    })
    $( "#slider-range" ).slider({
      range: true,
      min: 50,
      max: 10000,
      values: [ 75, 300 ],
      slide: function( event, ui ) {
        $( "#amount" ).val( $('select').val() + ui.values[ 0 ] + " - "+ $('select').val() + ui.values[ 1 ] );
      }
    });
    $( "#amount" ).val( $('select').val() + $( "#slider-range" ).slider( "values", 0 ) +
      " - "+ $('select').val() + $( "#slider-range" ).slider( "values", 1 ) );
  });
  </script>
</head>
<body>
<form action="bul.php" method="post">
<div style="margin-left:20px">
<select name=currency class="f15">
					<option value="" selected>TL</option>
					</select> 
    <label for="amount">Price range:</label>

    <input type="text" id="amount" name="amount" style="border:0; color:#f6931f; font-weight:bold;" readonly>
    <br><br>
    <div id="slider-range" style="width:80%;"></div>
    <br><br>
    <input type="submit" value="Show Prices " />
    <br><br>
</div>
</form>
</body>
</html>