Answers.Body: <p>Remember: all parameters in your <code>Query</code> are set to <code>null</code> by default. They won't be parsed into an <code>SQL</code> statement until they have a valid value (not <code>""</code>, not <code>NULL</code> not <code>0</code>) so you can just pass <code>null</code> values.</p>
  
  <pre><code>{% set range = null %}
  {% switch craft.request.getParam('sf') %}
      {% case '1' %}
          {% range = ['and', '&gt;=10000', '&lt;=20000'] %}
      {% case '2' %}
          {% range = ['and', '&gt;=20000', '&lt;=30000'] %}
  {% endswitch %}
  
  {% set query = craft.entries
      .city(craft.request.getParam('city')) // &lt;-- if city is null, nothing happens
      .buildingSQFT(range)
      .section('propertiesSection')
  %}
  </code></pre>
  
  <p>Keep in mind <code>query</code> is currently only a <code>Query</code> and not an array of entries. You can still attach your parameters</p>
  
  <pre><code>{% if craft.request.getParam('status') %}
      {% set status = craft.categories.group('propertyStatus').slug(craft.request.getParam('status').one()) %}
  
      {% do query.relatedTo(['and', {targetElement: status.id}]) %}
  {% endif %}
  
  
  {% set entries = query.all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T21:20:20.513Z
Answers.Text: This is the code that ended up working for my search based on your answer. How can I check a field called LSFAOffice OR LSFAOther for matches in the range?
          {% set range = null %}
              {% switch craft.request.getParam('sf-lease') %}              
                  {% case '1' %}
                      {% set range = ['and', '>=1', '<=2500'] %}   
              {% endswitch %}
              {% set params = params|merge({'LSFAOffice':range}) %}
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T22:58:41.073Z
Answers.Text: Please see this https://craftcms.stackexchange.com/questions/25986/how-to-get-entries-with-or
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-04T11:00:51.850Z
Answers.Text: So this is not possible in twig?
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-04T11:01:45.577Z
Answers.Text: Not without custom functions or filters
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T08:54:19.390Z
Answers.LastActivityDate: 2018-05-03T08:59:39.427Z
Answers.LastEditDate: 2018-05-03T08:59:39.427Z
Answers.UserDisplayName: Robin Schambach
Answers.Body: <p>Try using</p>
  
  <pre><code>{% set params = params|merge({'buildingSQFT': '&gt;= 10000 and &lt;= 20000'}) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T08:42:05.660Z
Answers.Text: That won't work because this will be parsed completely wrong, please take a look at `Db::parseParam` https://github.com/craftcms/cms/blob/develop/src/helpers/Db.php#L418 for all valid syntaxes
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T09:05:23.590Z
Answers.Text: @RobinSchambach You are totally right
Answers.UserDisplayName: RvdB
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T08:00:16.037Z
Answers.LastActivityDate: 2018-05-03T08:00:16.037Z
Answers.UserDisplayName: RvdB
Body: <p>I'm building a property search form and searching by different types of fields in Craft.</p>
  
  <p>Here are my questions:</p>
  
  <ol>
  <li><p>How can I get a list of the unique cities in the entries section to declare my form options?</p></li>
  <li><p>I'm stuck on searching by square feet.  (see # sf # section in my code) My plan is to let the user select from a few different ranges of square footage. What I was trying to accomplish below is if my search parameter is "sf=1", the field buildingSQFT is searched for numbers in between 10000 and 20000. I would then set up different ranges based on the parameter.</p></li>
  </ol>
  
  <p>I'm not sure if this is a good way to do this.  Your input has to how to best accomplish this is appreciated.</p>
  
  <pre><code>{% if not craft.request.isAjax %}
  {# set base params #}
  
  {% set params = {
      section: 'propertiesSection',
      limit: null
  } %}
  
  {% set relatedParams = ['and'] %}
  
  {# status #}
      {% if craft.request.getParam('status') %}
          {% set status = craft.categories.group('propertyStatus').slug(craft.request.getParam('status')) %}
          {% set relatedParams = relatedParams|merge([{ targetElement:status }]) %}
      {% endif %}
  
  
  {# city #}
      {% set city = craft.request.getParam('city') %}
      {% if city %}
          {% set params = params|merge({'city':city}) %}
      {% endif %}
  
  {# sf #}
      {% set sf = craft.request.getParam('sf') %}
      {% if sf == "1" %}
          {% set params = params|merge({'buildingSQFT':range(10000,20000)}) %}
      {% endif %}
  
      {# add relatedParams to params #}
      {% if relatedParams|length &gt; 1 %}
          {% set params = params|merge({'relatedTo':relatedParams}) %}
      {% endif %}                
  
      {% set entries = craft.entries(params).search() %}
  
      {% if entries|length %}
  </code></pre>
  
Tags: <search><number><range>
Title: Searching Number Field To See If It Falls In A Range
ThreadText: # Searching Number Field To See If It Falls In A Range
  
  (Asked by: username_0 on 2018-05-02)
  
  I'm building a property search form and searching by different types of fields in Craft.
  
  Here are my questions:
  
  1. How can I get a list of the unique cities in the entries section to declare my form options?
  2. I'm stuck on searching by square feet. (see # sf # section in my code) My plan is to let the user select from a few different ranges of square footage. What I was trying to accomplish below is if my search parameter is "sf=1", the field buildingSQFT is searched for numbers in between 10000 and 20000. I would then set up different ranges based on the parameter.
  
  I'm not sure if this is a good way to do this. Your input has to how to best accomplish this is appreciated.
  
  ```
  {% if not craft.request.isAjax %}
  {# set base params #}
  
  {% set params = {
      section: 'propertiesSection',
      limit: null
  } %}
  
  {% set relatedParams = ['and'] %}
  
  {# status #}
      {% if craft.request.getParam('status') %}
          {% set status = craft.categories.group('propertyStatus').slug(craft.request.getParam('status')) %}
          {% set relatedParams = relatedParams|merge([{ targetElement:status }]) %}
      {% endif %}
  
  {# city #}
      {% set city = craft.request.getParam('city') %}
      {% if city %}
          {% set params = params|merge({'city':city}) %}
      {% endif %}
  
  {# sf #}
      {% set sf = craft.request.getParam('sf') %}
      {% if sf == "1" %}
          {% set params = params|merge({'buildingSQFT':range(10000,20000)}) %}
      {% endif %}
  
      {# add relatedParams to params #}
      {% if relatedParams|length > 1 %}
          {% set params = params|merge({'relatedTo':relatedParams}) %}
      {% endif %}                
  
      {% set entries = craft.entries(params).search() %}
  
      {% if entries|length %}
  
  ```
  
  **Tags:** search, number, range
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-05-03. Score: 1
  
  Remember: all parameters in your `Query` are set to `null` by default. They won't be parsed into an `SQL` statement until they have a valid value (not `""`, not `NULL` not `0`) so you can just pass `null` values.
  
  ```
  {% set range = null %}
  {% switch craft.request.getParam('sf') %}
      {% case '1' %}
          {% range = ['and', '>=10000', '<=20000'] %}
      {% case '2' %}
          {% range = ['and', '>=20000', '<=30000'] %}
  {% endswitch %}
  
  {% set query = craft.entries
      .city(craft.request.getParam('city')) // <-- if city is null, nothing happens
      .buildingSQFT(range)
      .section('propertiesSection')
  %}
  
  ```
  
  Keep in mind `query` is currently only a `Query` and not an array of entries. You can still attach your parameters
  
  ```
  {% if craft.request.getParam('status') %}
      {% set status = craft.categories.group('propertyStatus').slug(craft.request.getParam('status').one()) %}
  
      {% do query.relatedTo(['and', {targetElement: status.id}]) %}
  {% endif %}
  
  {% set entries = query.all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: This is the code that ended up working for my search based on your answer. How can I check a field called LSFAOffice OR LSFAOther for matches in the range?         {% set range = null %}             {% switch craft.request.getParam('sf-lease') %}                               {% case '1' %}                     {% set range = ['and', '>=1', '<=2500'] %}                {% endswitch %}             {% set params = params|merge({'LSFAOffice':range}) %}  
  > **username_1**: Please see this https://craftcms.stackexchange.com/questions/25986/how-to-get-entries-with-or  
  > **username_0**: So this is not possible in twig?  
  > **username_1**: Not without custom functions or filters  
  
  ---
  
  ### Answer by username_2 on 2018-05-03. Score: 0
  
  Try using
  
  ```
  {% set params = params|merge({'buildingSQFT': '>= 10000 and <= 20000'}) %}
  
  ```
  
  > **Comments:**
  > **username_1**: That won't work because this will be parsed completely wrong, please take a look at `Db::parseParam` https://github.com/craftcms/cms/blob/develop/src/helpers/Db.php#L418 for all valid syntaxes  
  > **username_2**: @username_1 You are totally right  
  
  ---
  
  