Gossamer Forum
Home : Products : DBMan : Discussions :

Searching multiple categories from a select field

Quote Reply
Searching multiple categories from a select field
Hello,

I've done a lot of reading on different search options, and I think what I need to be done can be done, but I wasn't sure what information I found applied to my situation.

Here's what I need to do:

On a static web page, set up a search based on 3 drop-down menus, like this:

<form action="cgi-bin/dbman/db.cgi" method="GET">
<input type=hidden name="db" value="default">
<input type=hidden name="uid" value="default">

<select name="*"><OPTION VALUE="*">Search for a
<OPTION value="DIL">Drive In Lodge
<OPTION value="FIL">Fly In Lodge
<OPTION VALUE="BB">Bed and Breakfast
</select>
<br><select name="*">
<option VALUE="*">That offers...
<OPTION value="CO">Canoe Outfitting
<OPTION value="ECO">Eco Tours
<OPTION value="WA">Winter Accommodations</select>

<br><select name="*"><option VALUE="*">And provides...
<option value="AP">All meals
<option value="HK">No meals</select>

<INPUT TYPE="HIDDEN" NAME="mh" VALUE="10" SIZE=3>
<INPUT TYPE=HIDDEN NAME="sb" VALUE="ID">
<input type="submit" NAME="view_records" value="Go">
</form>

The problem is that each of these cryptic codes (AP, HK, CO, ECO, etc) are different categories in default.cfg, like this:

'HK' => [10, 'alpha', 0, 2, 0, '', ''],
'AP' => [11, 'alpha', 0, 2, 0, '', ''],
'MAP' => [12, 'alpha', 0, 3, 0, '', ''],
'PP' => [13, 'alpha', 0, 2, 0, '', ''],

Usually, you specify the category in <select name="category"> but since they're all different categories, I figured I'd have to do this by keyword?

If I do have to do this by keyword, would I have to implement part of the boolean MOD to allow AND searches? And what about exact matches. The code AP may match the word "apartment" for example in another field. I'd just want AP resuts returned.

I would appreciate any help anyone can give. Please!!
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
Seeing this line;

"cgi-bin/dbman/db.cgi"

...made me beleive that this was not a Links 2 related post, so I've moved it here for you Wink

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] Searching multiple categories from a select field In reply to
Bah! It was the end of the day when I posted it. This should be in DBMan Discussion, not SQL. One more move please. Sorry about that!
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
Whoops...I can't move it from here. Will have to get one of the mods to do it for this forum... Wink

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: [jadey] Searching multiple categories from a select field In reply to
I have a question for you.

Are the categories from the config file
Quote:
'HK' => [10, 'alpha', 0, 2, 0, '', ''],
'AP' => [11, 'alpha', 0, 2, 0, '', ''],
'MAP' => [12, 'alpha', 0, 3, 0, '', ''],
'PP' => [13, 'alpha', 0, 2, 0, '', ''],
just yes/no type of fields?

If so then I can perhaps there is a way to do it.

Please consider posting a portion of the .db and .cfg files as .txt files so we can get a better undersrtanding of the situation.
Quote Reply
Re: [joematt] Searching multiple categories from a select field In reply to
If they are checkbox fields then just setup your search form to show the various checkbox options.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Searching multiple categories from a select field In reply to
Thanks very much for your replies! Yes, these are simple yes and no type fields, but I have them set like this:

%db_checkbox_fields = (
'HK' => 'HK',
'AP' => 'AP',
'MAP' => 'MAP',
'PP' => 'PP',

I wanted to use drop-down menus as the format that I have has a really nice flow for users to find what they want. Basically asking questions, and selecting from the drop down menu what your answer is.
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
joematt, have I posted enough code for you to help with the select menus? If not, please let me know what else to post. Smile
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
I think that was enough code, as really the answer to the question was enough, after I re-read the original post.

I was really busy friday and did not check for a reply.

In one of my database searches I had a similar situation I solved that is like yours,... you want to do a keyword search, but skip some fields.

I will upload the section from my db.cgi that performs the task. It was my own "hack" and any comments from anyone are welcome as I am sure there is a more elagant way to do do the same thing. There even might be a MOD for this ....Please tell me if there is.

I hope you can understand it, as I am not sure I can explain it. It does work.
Quote Reply
Re: [joematt] Searching multiple categories from a select field In reply to
Thanks for the code joematt!

I added it to my db.cgi and was able to search my fields Smile First problem solved!

But it still only searches the first drop-down menu :( I need it to look at all 3.

I tried applying the boolean mod as well, but it still only searched the first field. I thought this may help. Here's the search URL passed (without the boolean mod)

http://www.mydomain.ca/cgi-bin/db/db.cgi?db=default&uid=default&ma=on&keyword=FIL&keyword=CO&keyword=AP&mh=10&sb=ID&view_records=Go

This in fact returns everything with the keyword FIL weather they have the keywords CO and AP or not. Unsure
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
Well good (and bad).

#1. I hope that you were able to determine which fields in YOUR database you wanted to eliminate from the search.

#2. I used "prodkeyword" not "keyword". I see from your URL that you are using "keyword=FIL". That will still activate the keyword search. You need to activate the hacked search routine using some other word.

Hope that helps.

Let me know.

Feel free to email me part or all of the db.cgi and/or html.pl.
Quote Reply
Re: [joematt] Searching multiple categories from a select field In reply to
I just keep bumping my head into a wall. Pirate

Thanks joematt for all your help on this thread & emails, I appreciate it very much!

I applied the hack joematt posted, and duplicated it twice to be able to search prodkeyword, servicekeyword and mealplankeyword. However, It would only search prodkeyword, no matter what I did.

joematt suggested I make one combined field with all values I needed to search. With the way I want to do the search, wouldn't I still need to apply the boolean mod? So.. I applied the boolean MOD, and the fix to search cross-fields. This allowed me to search either prodkeyword, servicekeyword OR mealplankeyword, but not all three Unsure

If I combined all the fields into 1 search, wouldn't I still have to have the boolean mod working to use 3 drop-down menus to search?

Again, any help is very much appreciated. Smile
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
I have prepared a file that I hope is a clear and accurate description of your question. It also contains the humble solution.
Quote Reply
Re: [joematt] Searching multiple categories from a select field In reply to
Great instructions joematt! Thanks again for all your help. Smile

Here's another solution that a friend worked out for me. This involves a search using a php script, but it will do exactly the kind of search that I wanted - 3 drop-down menus and the results with be only those that match ALL selections. Joematt's solution is perfect, but if you don't want to add extra fields for whatever reason, this will work too. I figured I'd post it for anyone who wants it.

Basically, the values in the 3 select menus are divided into 3 arrays. You pick which database fields you want searchable, and put them into the correct array. This one is set up for my database fields, but it's easy to change the fields.

I've attached the php search to this post. Once you've modified the code to match the fields you want to search, call the php script directly from the web. http://www.yourdomain.com/searchfile.php

The code my friend made prints out the entire record in the search results. I only wanted a name, with a click to "more details" which linked back into my dbman script. If you want to do this method, comment out (with // ) the 8 lines that start with:

for ($i = 1; $i <= 30; $i++) {

and end at:

}

(just before the next echo)

Then in the line, echo("<P>Record #".$ID." matches<BR>\n");

you can add the information you want instead. Here's mine:

echo("<P>Record #".$ID." matches<BR><b>$recordinfo[1]</b><br> <a href=\"cgi-bin/db/db.cgi?db=default&uid=default&view_records=View+Records&Title=$recordinfo[1]\" class=linksmenu>Click here for details...</a>\n");

$recordinfo[1] is the same as 1 in my database definition fields in default.cfg, which in my case is the business name. So this link searches dbman for the record with the same company name. You can search a different field of course.

Thanks to my friend Perrin for coming up with this! And thanks again to joematt too Smile

I'll try and field any questions I can about this if anyone else wants to try it Smile

Last edited by:

jadey: Nov 12, 2002, 12:04 PM
Quote Reply
Re: [jadey] Searching multiple categories from a select field In reply to
Hrm, wouldn't attach my text file for some reason. Posting it in the thread instead. Be sure to name the file with a .php extension, or whatever your server likes php files to be named. Posted by the author's permission. Distributed under the GPL: http://www.gnu.org/copyleft/gpl.html

Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE WIDTH=50><TR><TD>
<form action="<? echo($PHP_SELF)?>" method="GET">
<input type=hidden name="db" value="default">
<input type=hidden name="uid" value="default">
<tr>
<td>
<select name="Type">
<OPTION VALUE="">
Search for a
<OPTION value="DIL">
Drive In Lodge
<OPTION value="BIL">
Boat In Lodge
<OPTION value="FIL">
Fly In Lodge
<OPTION value="RIL">
Rail In Lodge
<OPTION value="BIO">
Boat In Outpost
<OPTION value="FO">
Fly In Outpost
<OPTION value="TP">
RV Park/Campground
<OPTION value="ECO">
Adventure Outfitter
<OPTION value="M">
Motel / Hotel / B&B
</select>
<br>
<select name="Services">
<option VALUE="">
That offers...
<option value="">
Fishing
<OPTION VALUE="HUNT">
Hunting
<OPTION value="CO">
Canoe Outfitting
<OPTION value="ECO">
Eco Tours
<OPTION value="WA">
Winter Accommodations
<OPTION value="DFO">
Daily Fly Out Fishing
</select>
<br>
<select name="Meal">
<option VALUE="">
And provides...
<option value="AP">
American Plan Packages
<option value="HK">
Housekeeping Plan
</select>
<br>

<INPUT TYPE="HIDDEN" NAME="mh" VALUE="10" SIZE=3 MAXLENGTH=3>
<INPUT TYPE=HIDDEN NAME="sb" VALUE="ID">
<INPUT TYPE=HIDDEN NAME="dosearch" VALUE=1>
<input type="submit" NAME="view_records" value="Go" align=right>
</form>
</TD></TR></TABLE>

<?
if ($dosearch==1) {
$logFile = file("./default.db");
while (list($key, $val) = each($logFile)) {
# Explode each line
$val = explode("\t",$val);

# Get Req'd Fields
$recordinfo = explode("|",$val[0]);
$ID=$recordinfo[0];
$HK=$recordinfo[11];
$AP=$recordinfo[12];
$MAP=$recordinfo[13];
$PP=$recordinfo[14];
$DR=$recordinfo[15];
$DIO=$recordinfo[16];
$HUNT=$recordinfo[17];
$WA=$recordinfo[18];
$DFO=$recordinfo[19];
$AS=$recordinfo[20];
$CO=$recordinfo[21];
$DV=$recordinfo[22];
$BIL=$recordinfo[23];
$FIL=$recordinfo[24];
$RIL=$recordinfo[25];
$BIO=$recordinfo[26];
$FO=$recordinfo[27];
$TP=$recordinfo[28];
$ECO=$recordinfo[29];
$M=$recordinfo[30];
$HB=$recordinfo[31];

$MEALS=array($HK,$AP,$MAP);
$OFFERS=array($PP,$DR,$HUNT,$ECO,$WA,$DFO,$AS,$CO,$HB);
$ACCOM=array($DV,$BIL,$FIL,$RIL,$DIO,$BIO,$FO,$TP,$M);

$MEALPLAN=$Meal;
$OFFER=$Services;
$ACC=$Type;
if (in_array($MEALPLAN,$MEALS)) {
if (in_array($OFFER,$OFFERS)) {
if (in_array($ACC,$ACCOM)) {
echo("<P>Record #".$ID." matches<BR>\n");
for ($i = 1; $i <= 30; $i++) {
echo($recordinfo[$i]);
if ($i < 11) {
echo("<BR>\n");
} else {
echo("&nbsp;&nbsp;");
}
}
echo("</P><HR>");
}
}
}


}
}
?>

</BODY>
</HTML>

Last edited by:

jadey: Nov 12, 2002, 12:30 PM