Gossamer Forum
Home : Products : DBMan : Installation :

search within range

Quote Reply
search within range
Hi,
I spent 2 hours to find it on the forum but I didn't... I want to do a search within two numbers. I read about the tip with <option> but it's not convenient. I have a field ('hommes') =numer It is a number of people, could be 1, 2, 10 etc... and I want people can search for =x people (that's the way it actually works) but also for <x or >x (that's ok with < and > ) AND for greater than x but less than x.
I tried >3<6 for example to find record with 4 and 5 people but that didn't work. Is there is a way to do it ?
Merci.
Quote Reply
Re: search within range In reply to
No. What you'll need to do on your search form is to create two fields -- hommes-gt and hommes-lt. If you enter the numbers in those fields, you'll get the search results you want.


------------------
JPD





Quote Reply
Re: search within range In reply to
Got it! Smile

In db.cgi, sub query, after

local ($sortby);

add

Code:
foreach $column (@db_cols) {
if ($in{$column} =~ /&/) {
@values = split ('&', $in{$column});
if ($values[2]) { next; } # Can't work with more than two numbers
$values[0] = int($values[0]); # Removes any letters that might be there
$values[1] = int($values[1]);
if ($values[1] < $values[0]) { next; } # First number must be less than second number
$in{"$column-gt"} = $values[0];
$in{"$column-lt"} = $values[1];
# If you want the range to be inclusive, use
# $in{"$column-gt"} = $values[0] - 1;
# $in{"$column-lt"} = $values[1] + 1;
}
}

I tested on my home computer and it seems to work just fine.


------------------
JPD





Quote Reply
Re: search within range In reply to
Yes but and also an other fields with 'hommes' for an exact search. Else people have to enter -lt 3 -gt 1 to find record with just 2. So that's 3 fields for each search.
I have 9 fields on 15 like that, you mean I have to make a form with 9*3+6= 33 fields !!!
Wouch the page will be long !
Is there is a way to do a symbol for that like: if the search is "1&5" the script will automatically understand -gt 1 and -lt5 ?
(of course the script compared numbers before to find wich one is greater to avoid that people who will put '6&1')
that's the way I see it but i'm completely nut in programming.
Merci Smile
Quote Reply
Re: search within range In reply to
It might be possible to do what you want. I'll need to think about it a bit. Smile


------------------
JPD





Quote Reply
Re: search within range In reply to
It's nice ! I was really happy to try it... but did not work for me. :'(
in the request i see:
&Hommes=5%267
instead of &Hommes=5&7

in .cfg the field is:
Hommes => [5, 'numer', 5, 5, 0, '', ''],

in my db most records contains just one number beetween | like that:
...|3|...

I don't have any clue. I tried different thing (also with all default files from you)but same results: no match...
Au secours !
Quote Reply
Re: search within range In reply to
Can I take a look at your database in action?

Also, it would help if you could set $db_debug=1; in the .cfg file.
------------------
JPD







[This message has been edited by JPDeni (edited September 02, 1999).]
Quote Reply
Re: search within range In reply to
Of course you can go to:
http://www.sarlat.com/scripts/bdd/db.cgi?db=ac&uid=default&view_search=1

and also browse:
http://www.sarlat.com/scripts/bdd/

I set debug on, and still no understand why it's not working. I notice that if we do 2&5 rec are right (but don't work) and if we do 5&2 rec are wrong...
a bientot
Quote Reply
Re: search within range In reply to
I think I have it figured out.

In the code I gave you, after

$in{"$column-lt"} = $values[1] + 1;

(I noticed you were using inclusive numbers.)

add

Code:
$in{$column}= '';

It was looking for both the "-gt," "-lt" and the actual field. No wonder it didn't work! Smile

(Are these lists of short plays that are available? I'm always interested in seeing what sort of things people are keeping track of with DBman. Smile )



------------------
JPD





Quote Reply
Re: search within range In reply to
Well that's ok now !!! Really nice. Thank you. And with your code I took a lesson of programing and so I add something. Because I know some people don't care I wanted that if they put 9&6 the script don't say "no match" so I change a little your code. But may be there is a better way to do it... Smile

code: --------------
foreach $column (@db_cols) {
if ($in{$column} =~ /&/) {
@values = split ('&', $in{$column});
if ($values[2]) { next; } # Can't work with more than two numbers
$values[0] = int($values[0]); # Removes any letters that might be there
$values[1] = int($values[1]);
if ($values[1] > $values[0]) { # If first number is less than second number
$in{"$column-gt"} = $values[0] - 1;
$in{"$column-lt"} = $values[1] + 1;
}
if ($values[1] < $values[0]) { # Else first number is greater than second number
$in{"$column-gt"} = $values[1] - 1;
$in{"$column-lt"} = $values[0] + 1;
}
$in{$column}= '';
}
}
--------------- end code

And now the new path to my db is:
http://www.artcomedie.com/bdd/db.cgi?db=ac&uid=default&view_search=1

So yes these lists are available. In fact I spent so many nights to do this site ! It's for my publisher, a friend. I do the mistake to push him to the web and to said "Come on, I will do it, don't worry" Smile
I'm tired but I'm happy the biggest part is now done and we're just have to wait for visitors.

I wonder if you had a thread before around the specific problem of french with éèêà... in a search ?
Merci

[This message has been edited by FdS (edited September 02, 1999).]
Quote Reply
Re: search within range In reply to
Excellent! It always pleases me when people can take my code further. It means they've learned something. Smile

I'm not sure about the problems with other characters. I may have to get back to you on that.


------------------
JPD