简体   繁体   English

如何在此PHP页面中使用简单的HTML选择替换此价格滑块? 选择选项可以传递2个值(最小和最大价格)吗?

[英]How can I replace this price slider with a simple HTML select in this PHP page? Can the select option pass 2 values (min and max price)?

I am pretty new in PHP and I am absolutly not into front end (I am more a Java backend guy) and I have the following problem (I think pretty simple to someone having some PHP\\frontend background). 我是PHP的新手,我绝对不涉足前端(我更是Java后端人员),并且遇到以下问题(对于具有某些PHP \\前端背景的人来说,我认为这很简单)。

I am working on a very old style PHP web application. 我正在开发一个非常旧的PHP Web应用程序。

Into a page I have a form containing a price slector through which the user can choose a price range for a searchedproduct (something like from 50$ to 100$ ). 进入页面后,我有一个包含价格分段器的表单,用户可以通过该表单为搜索到的产品选择价格范围(例如从50 $到100 $ )。 Using the selector the use chose the min prince and the max prince in the range. 使用选择器,使用者在范围内选择了最小王子和最大王子。 For the slider it is using this JavaScript library: https://refreshless.com/nouislider/ 对于滑块,它正在使用以下JavaScript库: https : //refreshless.com/nouislider/

This is the price range slider into the PHP code of my search page: 这是我搜索页面的PHP代码中的价格范围滑块:

<div class="nouislider-wrapper">
    <div class="nouislider" data-min="0" data-max="<?php echo $max_price; ?>" data-start="<?php echo "[".$price_min.",".$price_max."]"; ?>" data-step="10" data-direction="<?php echo RTL_DIR; ?>" data-input="price_range"></div>
    <?php echo $texts['PRICE']." / ".$texts['NIGHT']; ?> : <?php echo CURRENCY_SIGN; ?> <input type="text" name="price_range" class="slider-target" id="price_range" value="" readonly="readonly">
</div>

Ok, from what I have understood it simply put the min price into a $price_min and the max price into the $price_max . 好的,据我了解,它只是将最低价格放入$ price_min ,将最高价格放入$ price_max

I need to remove the previous slider and replace it with a simple dropdown menu, something like a simple HTML select tag, something like this: 我需要删除以前的滑块,并用一个简单的下拉菜单替换它,例如一个简单的HTML select标记,如下所示:

<select>
    <option value="XXX">50$-100$</option>
    <option value="YYY">100$-150$</option>
    <option value="ZZZ">150$-200$</option>
    <option value="WWW">200$+</option>
</select> 

My problem is: how can I pass the 2 values (for example 50 and 100) when an user select a voice from this select tab? 我的问题是:当用户从此选择选项卡中选择语音时,如何传递2个值(例如50和100)? Is it possible pass the 2 values ( $price_min and $price_max ) into an option element of a select tag? 是否可以将2个值( $ price_min$ price_max传递select标签的option元素中?

If it is possible I prefear don't change logici (passing other values) because it is a very legacy application and it could be complicated handle the changes it the backend that uses these values, so if I can do it in the select it's better. 如果可能的话,我不担心不要更改逻辑值(传递其他值),因为这是一个非常旧的应用程序,并且可能会很复杂地处理使用这些值的后端的更改,因此,如果我可以在选择中进行更改,那会更好。

What do you think about it? 你怎么看待这件事?

you can not pass both value separately in selecttag but you can do it like 您不能在selecttag中分别传递两个值,但可以这样做

<select name="range">
    <option value="<?php echo $price_min.'-'.$max_price; ?>"><?php echo $price_min.'$-'.$max_price.'$'; ?></option>
</select>

now you have to do some stuff in php side 现在您必须在php端做一些事情

<?php
// suppose you select 50$-100$ you get 50-100 in $range 
$range = $_POST['range'];
$values = explode("-",$range);
$min_value = $values[0]
$max_value = $values[1] 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM