Gossamer Forum
Home : Products : DBMan : Customization :

Filter search results

Quote Reply
Filter search results
How can I filter the search result within a given month? What I mean is that when the viewer want to search for a party event within a particular month, how can I make the search return all the results within that month?

Please visit my database for more ideas of what I mean here.

http://www.melbourneraves.f2s.com/cgi-bin/events.cgi

login: guest
password: guest

Best Regards,

Quote Reply
Re: Filter search results In reply to
Welp, since you do not have a separate Month field, this would be highly problematic...The easiest solution is to add the following fields in your default.cfg file:

Month
Day
Year

(There is an upgrade script in the Resource Center that will add these new fields into your default.cfg file. The Month field should be alpha, the Day field should be numer, and the Year field should be numer)

Now in terms of adding and modifying records, you can do the following:

1) Copy the following sub-routine in your html.pl file:

Code:

sub build_fancy_select_field {
# --------------------------------------------------------
# Fancy Display of Fields.

my $field = $_[0];
my $compare = $_[1];
my %selector = (
'Day' => [
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19'],
['20','20'],
['21','21'],
['22','22'],
['23','23'],
['24','24'],
['25','25'],
['26','26'],
['27','27'],
['28','28'],
['29','29'],
['30','30'],
['31','31']
],
'Month' => [
['Jan','January'],
['Feb','February'],
['Mar','March'],
['Apr','April'],
['May','May'],
['Jun','June'],
['Jul','July'],
['Aug','August'],
['Sep','September'],
['Oct','October'],
['Nov','November'],
['Dec','December']
],
'Year' => [
['2000','2000'],
['2001','2001'],
['2002','2002'],
['2003','2003'],
['2004','2004'],
['2005','2005'],
['2006','2006'],
['2007','2007'],
['2008','2008'],
['2009','2009'],
['2010','2010']
],
);
$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$selector{$field}[$i][0] eq $compare ?
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
++$i;
}
if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}


2) Then in your sub html_record_form, add the following codes:

Code:

Day: |; print &build_fancy_select_field("Day", "$rec{'Day'}"); print qq|
Month: |; print &build_fancy_select_field("Month", "$rec{'Month'}"); print qq|
Year: |; &build_fancy_select_field("Year", "$rec{'Year'}"); print qq|


3) Then in your sub html_record and/or sub html_record_long routines, simply add the following codes:

Code:

Date: $rec{'Day'}-$rec{'Month'}-$rec{'Year'}


Now if you have the What's New Mod, you will have tweak the codes a bit to use these three fields.

That should do it...since the sub html_view_search routine[/b] will pull the values from the sub html_record_form.

Hope this helps.

Regards,

Eliot Lee
Quote Reply
Re: Filter search results In reply to
Hello there,

I've already tried those three steps but still can't use either the month or day to search or modify records. The only thing it works is the drop down list. Please kindly advise. Thank you so much!!! :)

p.s. I can't find the stuff you mentioned in the Resource Center. Do I need that anyway?

Many thanks,
Aladdin

Quote Reply
Re: Filter search results In reply to
If you already have an existing database and you have added the three new fields in the default.cfg, then you need to update your database with the Upgrade your Database script located in the DBMAN: Modification section in the Resource Center OR use a text editor like TextPad or EditPlus to update the databases.

http://www.textpad.com
http://www.editplus.com

Regards,

Eliot Lee
Quote Reply
Re: Filter search results In reply to
Thanks for your reply. Oh dear.. How stupid I am. I am sorry to tell you that I still dunno how to modify the default.cfg. Could u give me the codes instead? I'm still using the original default.cfg (without any modification on any fields) I don't care my old database, I just want to search an item by the month/day/year. Please advise again and it's my pleasure to get some more details if possible. Sorry for my bad English and many many thanks again!!!!

Thanks for your time! :-)

p.s. I've already followed your instructions and made the modifications (as you mentioned in the last few messages before) to the html.pl

Cheers,
Aladdin

Quote Reply
Re: Filter search results In reply to
It really is better if you set up your database the way you want it to be before you start modifying the script.

If you need help setting up the database, use the link under my signature to go to my tutorial on working with DBMan. You will be much better off if you are using your own database.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Filter search results In reply to
Thanks JDP!!

I eventually set up my own database and gonna start modifying the script. Would you plz gimme some clue how can the records be sorted by the month/day?

Here is the stuff you might interest:

%db_def = (
ID => [ 0, 'alpha', 5, 8, 1, '', ''],
Category => [ 1, 'alpha', 0, 255, 1, '', ''],
Description => [ 2, 'alpha', '40x3', 500, 0, '', ''],
Owner => [ 3, 'alpha', 0, 60, 1, '', ''],
Date1 => [ 4, 'date', 12, 15, 1, &get_date, ''],
Date2 => [ 5, 'date', 12, 15, 1, &get_date, ''],
Date3 => [ 6, 'date', 12, 15, 1, &get_date, ''],
Comment => [ 7, 'alpha', '40x3', 500, 0, '', ''],
Status => [ 8, 'alpha', 0, 60, 1, '', ''],
Priority => [ 9, 'alpha', 0, 60, 1, 'Normal', ''],
Reminder => [10, 'alpha', 0, 3, 0, '', ''],
Userid => [11, 'alpha', -2, 15, 0, '', '']
);

Thanks for your time!! :)

Aladdin

Quote Reply
Re: Filter search results In reply to
You're going to have three dates in each record? And they're all going to be the date the record is added? I'm confused.

To sort search results by any field, you just have to set the "so" field. You can either set it in a form or in a link. Rather than give both of them to you right now, can you tell me which one you want?

Regarding your searching by a given month (or any partial date), all you have to do is change one line in sub query.

Delete the code in red that's below:

Code:

if ($in{$column} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{$column}) or return "Invalid date format: '$in{$column}'");
push(@search_fields, $i); $i++; next; }
Make sure you get the right set of lines. There are 5 lines in sub query that begin in much the same way. This is the third one.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Filter search results In reply to
hi JPD

Opps.. Sorry. Wink I think I did something wrong. I should take away the &get_date and shouldn't set the current date as default. The reason why I set it up since I wanna let users to have a better idea of what the date format is. Sorry to make you feel confused. Frown

In Reply To:
To sort search results by any field, you just have to set the "so" field. You can either set it in a form or in a
link. Rather than give both of them to you right now, can you tell me which one you want?
"so" field??? Tongue *sigh* I couldn't get what you are saying... sorry. Anyway, I'd rather set it in a form.

In Reply To:

Delete the code in red that's below:

if ($in{$column} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{$column}) or return "Invalid date format: '$in{$column}'");
push(@search_fields, $i); $i++; next; }
But do I have to add/change anything else in order to make use of it?

Cool Thanks for your advice!! I'll try your codes at once.

Aladdin

Quote Reply
Re: Filter search results In reply to
In Reply To:
The reason why I set it up since I wanna let users to have a better idea of what the date format is.
Oh. I see. Well, it makes a little more sense now. Smile

In Reply To:
"so" field???
Actually, I mistyped. It should be the "sb" field. That stands for "sort by."

In the html.pl file, sub html_search_options, there is the following code:

Code:

Sort By:
<SELECT NAME="sb">
<OPTION>---
~; for (my $i =0; $i <= $#db_cols; $i++) { print qq~<OPTION VALUE="$i">$db_cols[$i]</OPTION>\n~ if ($db_form_len{$db_cols[$i]} >= 0); } print qq~
</SELECT>
This allows users to sort by any field they want to select from a drop-down select field. If you would rather have all results sorted by a specific field every time anyone does a search, replace the code above with

<input type="hidden" name="sb" value="the number of the field you want to sort by">

In Reply To:
<<Delete the code in red that's below:>>
But do I have to add/change anything else in order to make use of it?
Nope. This will allow users to sort by either whole dates or partial dates. However, if they search for a whole date and they have the format wrong, they will not get any search results.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Filter search results In reply to
In Reply To:
Nope. This will allow users to sort by either whole dates or partial dates. However, if they search for a whole date and they have the format wrong, they will not get any search results.
Cool! Cool Thxs God! I ended up get it worked! JPD, You are wonderful! Smile

P.S. Sorry, I got another little question for you. Wink I think I got something wrong with the &html_record in html.pl. When I select "List All", it doesn't display the content of the field "Comments" in multiple lines. Conversely, it only display one-line comment and, if user enters tons of words inside that field, it will create a very very big table and user has to scroll-right/left the bar to see the content of the comments. Frown

Aladdin

Quote Reply
Re: Filter search results In reply to
There are two things at work here.

Let's take the "tons of words" problem first. Are you sure that it's really words that you're entering, or have you done a test by holding down one key and printing it 100 or more times? If it's the latter, you need to not do that. In your test record, use real words with spaces between them. The text should wrap at the spaces.

Regarding the multiple lines -- you need to add a line to the beginning of sub html_record--

after

my (%rec) = @_;

add

$rec{'Comments'} =~ s/\n/<BR>/g;



JPD
http://www.jpdeni.com/dbman/