Range filtering with numeric values in a text input field
This is an open discussion with 4 replies, filed under Troubleshooting.
Search
I presume you're using a Text Input as the field. This stores as a varchar
in the database and so isn't best suited for numeric calculations. Primarily, you cannot order it numerically (1, 2, 10, 20), only alphabetically (1, 10, 2, 20). Text Inputs don't support range based filtering, so using a filter of 2-100
will try to match a string value of literally 2-100
, as opposed to evaluating it as a range.
I suggest using the Number field extension which looks and acts the same as a Text Input except you can sort numerically. I'm not sure what filtering capability it provides though. I can see from the code it supports mysql:...
as a data source prefix, so your filter might look like:
mysql: 4
Perhaps it supports BETWEEN
or <
and >
but I'm not sure.
Ah, fantastic, that makes sense :)
Thank you very much, huge help! I will use the Numeric Field and play around with the mysql: prefix.
All the best and thanks again.
You're welcome.
I've had a little experimentation myself, and it seems anything after mysql:
gets used as the expression. So range filtering directly in SQL you might use:
WHERE field BETWEEN 1 and 20
Which equates to a data source filter:
mysql: BETWEEN 1 and 20
or
WHERE field > 20
Which would be:
mysql: < 200
Ah good news. I haven't quite got it set up yet, doing so now.
Create an account or sign in to comment.
Hi,
I'm trying to add a data source filter rule to:
I am having trouble in that I can't get the Range Operators to work in the data source filter rules.
To help me explain this problem I have set up a section "Test" with one field "Field" it has the numeric validation rule.
I have created multiple entries with the following values in "Field": 6, 60, 101, 1, 050 and 0.
Then, I created a data-source "Test" and added it to a page.
On this data-source I added a validation rule for "Field" it was 2 to 100.
I have also tried 2-100, 2 - 100, >2. None of these return any results.
The simple filter 60 does return a result as expected.
I am using Symphony 2.2.2.
Hope I'm being clear enough! I would appreciate your help :-D