Gossamer Forum
Home : Products : DBMan : Customization :

range search: change greater than, less than into from, to search?

Quote Reply
range search: change greater than, less than into from, to search?
Currently I have several fields users search using greater than, less than range searches.

However, it seems most of my visitors expect and would be more comfortable with from-to search ranges.

What I mean is that &length-gt=10&length-lt=20 returns 11-19 but they expect it will return 10-20.

(I use this for years, lengths, etc. so when they search greater than 1998 and less than 2000 even though it specifically says older than and newer than, they expect it is from 1998 through 2000 including 1998 and 2000 or from 10' to 20' including 10' and 20'.)

Anyone know how to make the search basically add or subtract 1 to include the less than and greater than values entered in the less than, greater than search making it a from-to or actually from-through search?
Quote Reply
Re: [Jeff-C] range search: change greater than, less than into from, to search? In reply to
Look for
Code:
# Greater then searches.
foreach $field (@search_gt_fields) {
$term = $in{"$db_cols[$field]-gt"};

add
Code:
if ($db_sort{$db_cols[$field]} eq 'numer') {
$term = $term - 1;
}

A little below that, look for
Code:
# Less then searches.
foreach $field (@search_lt_fields) {
$term = $in{"$db_cols[$field]-lt"};

add
Code:
if ($db_sort{$db_cols[$field]} eq 'numer') {
$term = $term + 1;
}

This will only work for numeric values. Dates and characters are a whole lot more complicated.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Aug 20, 2005, 8:42 PM
Quote Reply
Re: [JPDeni] range search: change greater than, less than into from, to search? In reply to
Wow - you are simply amazing! Once again, works like a charm! Implemented the change and already got a thank-you from a user who emailed to complain they couldn't find their own record earlier tonight! Thanks so much as always for your incredible help!!
Quote Reply
Re: [Jeff-C] range search: change greater than, less than into from, to search? In reply to
You're very welcome. It all comes from spending an inordinate amount of time looking at the script, so I can figure out what section the change needs to go in.

I'm really glad it worked for you and your users. :-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.