Answers.Body: <p>Aha! Another lightbulb moment.</p>
  
  <p>The wage field was set to be plain text. I changed it to number and things work as expected.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T15:28:17.030Z
Answers.Text: Yup!  That's because MySQL/PHP handle string comparisons of numbers different than integer comparisons of numbers.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T16:28:01.647Z
Answers.Text: I figured that's what the problem was. I was trying to change the type in my template rather than just change the field type. This is only my 2nd Craft project and the other was a simple prototype. I'm still learning! :)
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T13:56:49.120Z
Answers.LastActivityDate: 2015-10-12T13:56:49.120Z
Answers.UserDisplayName: foamcow
Body: <p>Following on from my earlier search question...</p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/11862/searching-for-entries-across-multiple-fields-including-a-relationship/11863">Searching for entries across multiple fields including a relationship</a></p>
  
  <p>I'm finding that the min/max wage search behaves oddly.</p>
  
  <p>I have a range of wage values from 95 to 175. </p>
  
  <p>If I search for a min of 95 with no max then I only get results from 95 up to 100.</p>
  
  <p>Likewise if I search for a max value of 150 then I only get results greater than 100 and less then or equal to 150.</p>
  
  <p>If I use both min and max criteria then I get no results.</p>
  
  <p>I'm guessing this is something to do with variable type but can't see how I can force the variables to be integers/numbers rather than strings.</p>
  
  <p>The simplified code I'm using to do the matching is:</p>
  
  <pre><code>{% set wage_from = craft.request.getParam('wage_from') ? craft.request.getParam('wage_from') : 0 %}
  {% set wage_to = craft.request.getParam('wage_to') ? craft.request.getParam('wage_to') : 9999 %}
  
  {%
    set results = craft.entries({
        section: 'vacancies',
          wage: [
            'and',
            '&gt;= ' ~ wage_from,
            '&lt;= ' ~ wage_to,
          ]
      })
  %}
  </code></pre>
  
Tags: <search><variable-type><integer>
Title: Min/Max numeric search returning odd results
ThreadText: # Min/Max numeric search returning odd results
  
  (Asked by: username_0 on 2015-10-12)
  
  Following on from my earlier search question...
  
  [Searching for entries across multiple fields including a relationship](https://craftcms.stackexchange.com/questions/11862/searching-for-entries-across-multiple-fields-including-a-relationship/11863)
  
  I'm finding that the min/max wage search behaves oddly.
  
  I have a range of wage values from 95 to 175.
  
  If I search for a min of 95 with no max then I only get results from 95 up to 100.
  
  Likewise if I search for a max value of 150 then I only get results greater than 100 and less then or equal to 150.
  
  If I use both min and max criteria then I get no results.
  
  I'm guessing this is something to do with variable type but can't see how I can force the variables to be integers/numbers rather than strings.
  
  The simplified code I'm using to do the matching is:
  
  ```
  {% set wage_from = craft.request.getParam('wage_from') ? craft.request.getParam('wage_from') : 0 %}
  {% set wage_to = craft.request.getParam('wage_to') ? craft.request.getParam('wage_to') : 9999 %}
  
  {%
    set results = craft.entries({
        section: 'vacancies',
          wage: [
            'and',
            '>= ' ~ wage_from,
            '<= ' ~ wage_to,
          ]
      })
  %}
  
  ```
  
  **Tags:** search, variable-type, integer
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-10-12. Score: 2 | Accepted answer
  
  Aha! Another lightbulb moment.
  
  The wage field was set to be plain text. I changed it to number and things work as expected.
  
  > **Comments:**
  > **username_1**: Yup!  That's because MySQL/PHP handle string comparisons of numbers different than integer comparisons of numbers.  
  > **username_0**: I figured that's what the problem was. I was trying to change the type in my template rather than just change the field type. This is only my 2nd Craft project and the other was a simple prototype. I'm still learning! :)  
  
  ---
  
  