Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Search with checkboxes

Quote Reply
Search with checkboxes
Hi! Have searched the forums but find no conclusive answers about incorporating checkboxes on an advanced search page. Using the code below, for example, works if the user checks ONE box, but doesn't work if s/he checks two boxes or more boxes. This sort of search works in the Admin panel, so why can't it work on the site?!?Cool

<B>Accommodation:</B><BR>Guest House <INPUT TYPE="CHECKBOX" NAME="Accommodation" VALUE="Guest House"> Hotel<INPUT TYPE="CHECKBOX" NAME="Accommodation" VALUE="Hotel">Local Host Family <INPUT TYPE="CHECKBOX" NAME="Accommodation" VALUE="Local Host Family">Student Residence<INPUT TYPE="CHECKBOX" NAME="Accommodation" VALUE="Student Residence">

search.cgi?Accommodation=Guest+House This works OK
search.cgi?Accommodation=Hotel This works OK

search.cgi?Accommodation=Guest+House&Accommodation=Hotel This does NOT work

This has nothing to do with the entries in the db. Plenty of entries contain both values.

I know it can be done with radio buttons, but that doesn't offer the flexibility of checkboxes to search for two items at once. As it can be done in Admin, I wonder why it doesn't work on the site. What am I doing wrong?!

Many thanks for any help.

Josef

Thanks,
--Jo
Quote Reply
Re: [iplay] Search with checkboxes In reply to
I've just run into this problem too Unsure.

Can anyone from GT comment on why this technique works fine in the admin panel but not in search.cgi?
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
I've also tried using a multi select box in the form instead of checkboxes and it still does not work as it does in admin.cgi.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Hi,

Any examples? Should work fine with any of those.

It just passes multiple paramaters along, i.e:

search.cgi?query=xxx;checkboox_field=value_1;checkboox_field=value_2

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Search with checkboxes In reply to
Andy, I'd prefer not to post a link in the forums but I'll send you a PM. Looks like a possible bug to me but I'd be interested in a second opinion.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Hi,

No problem - I'll take a look once you've sent the PM Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [iplay] Search with checkboxes In reply to
We are using advanced search function with a combination of checkbox, radio, dropdown and multiselect all together. Hope this helps:

http://www.webhostingkit.com/a/cgi/search.cgi

Hope this helps.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Search with checkboxes In reply to
Vishal, we can run the searches ok but the numbers don't add up - Andy has had a look for me and he agrees it may be a potential bug.

I'm not sure if it's working on your site either. If you select both 'Windows' and 'FreeBSD' under the Platform option, there are a lot of results returned that do not offer both platforms. I would be interested to know how many results you get when doing this same search in the admin panel?
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Search works just fine for me, give me an example please.

I tested with just win & bsd search and that worked too.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Search with checkboxes In reply to
Vishal, I don't think you are using the Platform field in the same way. Each of your plans only has one platform so you don't have records with multiple values stored e.g. Windwos and OSX on one plan.

If you store multiple values in the checkbox/multi value field then the problems occur.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Let me rephrase it just so I understand it right.

You mean to say an option where a link can have more than one value selected and then user is allowed to choose one or more options in advanced search page, right?

It also seemed to have worked just fine for me with the same settings as that I am using for Web Hosting Kit. I am using advanced search function on Software Devil (it is not public yet) and one a clients site, which their staff has been using for few months without any problem.

Here is an example of what I am using on Software Devil.

When user is adding a link, there are following options for operating system there are 18 checkboxes options. For not a single listing all the options will be selected, however for many listings there are 2 to 8 options selected and you are able to do a search from admin section and also from template section using your choice of operating.

Like many other members you have been a great help to me, so if you want to see it in action, send me a pm or get on yahoo im.. I am in hospital cuz of surgery, however should be able to setup something for you that could help you solve the problem or when I am feeling better. I will just create a demo page and post it here for everyone to see.

P.S.. Special thanks goes to Andy and Laura for the advanced search I have been able to setup.. in the past I have asked both of them tons of questions and with combined knowledge of all that this search function was pretty easy to setup.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Search with checkboxes In reply to
SWDevil.Com wrote:
You mean to say an option where a link can have more than one value selected and then user is allowed to choose one or more options in advanced search page, right?
Yes, but when the user chooses two of the 'same' option (say Windows and FreeBSD on your site) then the search should find links that have both these options, not either of these options. That's how the admin panel search works but it doesn't seem to work that for me with search.cgi, or the original poster if they are still around Wink.

I might look around at a few other Links sites and see if I can work out what's going on. If I can't I'll get back to you as you have a pretty complex search form and there's probably something in there I can learn from.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
aus_dave wrote:
SWDevil.Com wrote:
You mean to say an option where a link can have more than one value selected and then user is allowed to choose one or more options in advanced search page, right?
Yes, but when the user chooses two of the 'same' option (say Windows and FreeBSD on your site) then the search should find links that have both these options, not either of these options. That's how the admin panel search works but it doesn't seem to work that for me with search.cgi, or the original poster if they are still around Wink.

I might look around at a few other Links sites and see if I can work out what's going on. If I can't I'll get back to you as you have a pretty complex search form and there's probably something in there I can learn from.

This is what I did right now to test it for you:

1. In Advanced search page, left everything untouched and only selected Windows OS
2. In Advanced search page, left everything untouched and only selected FreeBSD
3. In Advanced search page, left everything untouched and only selected Windows & FreeBSD

When you do the total of the results, you will notice that the total is same.

P.S... there are only 2 listings FreeBSD, which are test listings added by me.

Vishal
-------------------------------------------------------
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
oh I think now I understand what you mean. The searches on the website are set as 'either' windows 'or' freebsd', so it will display ALL plans with Windows and ALL the plans with FreeBSD. Now cuz its a hosting directory, I doubt anyone would be searching for a server with windows and freebsd together in it.

However what you are looking for is:

1. If out of options a, b, c, d and e. if user chooses c and e. Than you want only those listings to show up that have both 'c' and 'e' and not listings with only 'c' or only 'e', am I right?

Vishal
-------------------------------------------------------
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Can you give me a search url (with the search terms) where it's broken? I'm not sure I understand the problem.

Adrian
Quote Reply
Re: [SWDevil.Com] Search with checkboxes In reply to
SWDevil.Com wrote:
If out of options a, b, c, d and e. if user chooses c and e. Than you want only those listings to show up that have both 'c' and 'e' and not listings with only 'c' or only 'e', am I right?
That's exactly right. I'd be interested to know how you configured your search form for the 'OR' Platform option rather than 'AND', and also what your admin search function shows when you search for both 'Windows' and 'FreeBSD' - if it behaves as I think it does it should show no results on your site.

brewt wrote:
Can you give me a search url (with the search terms) where it's broken? I'm not sure I understand the problem.
PM sent.
Quote Reply
Re: Search with checkboxes In reply to
aus_dave wrote:
or the original poster if they are still around Wink

Still here Smile Was there any resolution to this problem?

Thanks,
--Jo

Last edited by:

iplay: May 3, 2008, 10:11 AM
Quote Reply
Re: [iplay] Search with checkboxes In reply to
Adrian looked into this for me but he couldn't replicate it on his system. We had limited access to full error logs etc. on our previous server so that wasn't much help either.

It's still a problem for us and I have contemplated moving all of these options to their own fields just to get around this issue - it will make the database a lot more untidy but if it solves the problem I can live with it.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
If anyone is having this problem and has ssh access to their server with access to their webserver's access/error logs, pm them to me and I'll take a quick look. Also include all the necessary steps/urls to replicate the problem.

Adrian
Quote Reply
Re: [brewt] Search with checkboxes In reply to
Adrian, we've recently had to move our site to a server with SSH access - I'll PM you the details.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
Okay, here's what's going on:

aus_dave is using a single VARCHAR column with the form_type set to MULTI-SELECT. Internally, when you save such a field with multiple values, all the values get concatenated together with a newline separator. However, for searching (at least non-admin search) it currently doesn't change the search to handle that change. I haven't decided what the best way to correct this issue right now, but a temporary solution would be to modify Links/User/Search.pm, to add the following just before the line "my $link_sth = $links->query_sth($args)":
Code:
foreach (keys %{$links->cols}) {
next unless ref $args->{$_} eq 'ARRAY';
if (exists $args->{"$_-opt"} and $args->{"$_-opt"} eq 'LIKE') {
$args->{$_} = join("%", sort @{$args->{$_}});
}
}
You also need to change your form to add in an <input type="hidden" name="ColumnName-opt" value="LIKE" />

I'd just like to point out that this database structure isn't the best one. First, it's fairly wasteful in terms of database storage, second, it's not very efficient with searching, and lastly, it can be plain wrong with search results if one of your values can be a part of another value (eg. "col" and "column"). If you have a limited number of possible options, then it's probably better to use a column for each option where the value is a TINYINT of 0 (No) or 1 (Yes).

Adrian
Quote Reply
Re: [brewt] Search with checkboxes In reply to
Thanks for looking into this for us Adrian.

We only use this field as a checkbox within search forms and the various options are distinct enough that we don't run into issues with duplication. How many different options would you say is a 'limited' number? We currently have 11 options that we handle in this field, we seem to add one every so often as they are requested by our site members.

I thought having these in one field would be more efficient but it sounds like it might be better to put them all in their own field. I'm mindful of increasing the size of our editing/validating forms though, they are complex enough as it is Unsure.
Quote Reply
Re: [aus_dave] Search with checkboxes In reply to
I would say 10 options is fine. If they're TINYINT's, they only should take up 1 byte of space. This vs your VARCHAR maximum size of 60.

Adrian