简体   繁体   English

下拉选项值 - 不小于

[英]Dropdown option value - no less than

I am working on a real estate website and require dropdown fields for minimum bedrooms, bathroom etcs using a simple html code:我在一个房地产网站上工作,需要使用简单的 html 代码为最小卧室、浴室等提供下拉字段:

 <select class="facetwp-dropdown" id="id_beds_min" name="beds_min"> <option disabled selected value>Beds</option> <option value="1">1+</option> <option value="2">2+</option> <option value="3">3+</option> <option value="4">4+</option> </select>

I know that the fields need conditions - ie that it cannot be less than 1, or 2 etc. But not quite sure on the coding.我知道这些字段需要条件 - 即它不能小于 1 或 2 等。但对编码不太确定。

I'm using a plugin called FacetWP to assist with the search fields.我正在使用一个名为 FacetWP 的插件来协助搜索字段。

Any assistance?任何帮助?

I would completely remove the options you want to disable:我会完全删除您要禁用的选项:
Within the html code (in this code where <option value="1">1+</option> is), call a function in brackets: {this.renderNumberOfBedOptions(minNumberOfBedOptions, maxNumberOfBedOptions)}在 html 代码中(在此代码中<option value="1">1+</option>所在的位置),调用括号中的函数: {this.renderNumberOfBedOptions(minNumberOfBedOptions, maxNumberOfBedOptions)}

Then, above the html code inside the javascript code:然后,在 javascript 代码中的 html 代码上方:

    renderNumberOfBedOptions{minNumberOfBedOptions, maxNumberOfBedOptions) {
       let options;  
       for (let i = minNumberOfBedOptions; i < maxNumberOfBedOptions; i++) {
          options += <option value=i>i+</option>
       }
       return options;

Your html should be somthing like this:你的 html 应该是这样的:

<select class="facetwp-dropdown" id="id_beds_min" name="beds_min">
<option disabled selected value>Beds</option>

<?php 

for($i=$minbeds; $i<=maxbeds; $i++)
{

    echo "<option value=".$i.">".$i."+</option>";
}
?> 
  </select> 

What you do next in the server side is query with something like this:你接下来在服务器端做的是这样的查询:

$bedrooms_min = $_POST["beds_min"];
query = "select*  from houses where bedrooms >=".$bedrooms_min

and consider using mysqli prepared statements.并考虑使用 mysqli 准备好的语句。 if your html template contains no php code you can convert the loop to JavaScript after querying the minimum and maximum number of rooms from the back end but WordPress templates can contain php code anyway.如果您的 html 模板不包含 php 代码,您可以在从后端查询最小和最大房间数后将循环转换为 JavaScript,但 WordPress 模板无论如何都可以包含 php 代码。

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

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