Gossamer Forum
Home : Products : DBMan : Discussions :

how to search for keywords, only if field2=active?

Quote Reply
how to search for keywords, only if field2=active?
I am just starting to learn DBMan so I can add a public search function for a pre-existing database.

I am currently using a query like:
http://mydomain.com/cgi-bin/db.cgi?db=default&keyword=kayak&view_records=View+Records which works great, except that I need to only return results which have status=active (field 2 in the db is named status, and sites are either active or inactive. I don't want the inactive sites showing up in the search results as these have not been validated yet.)

How can this be done?

P.S. I am searching by keywords because I need to search the Title, Description, and URL fields from one public search form field. Thanks.

Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Quick way:

Wrap your entire record code in html_record in an if statement. eg:

if (($rec{'Validated'} eq 'Yes') || $per_admin) {
...HTML for record...
}


Longer way:

Get the validate MOD. It's a MOD written by JPDeni for DBMan which allows an admin to approve newly added (and optionaly, mofified) records to the database. Un-Validated records are kept hidden until validated, and it inlcudes a mail-out feature which emails the user to tell them their record has either been validated or denied.

Cheers,

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Re: Quick way

I've now changed the sub build_html_record in db.cgi to:
Code:
sub build_html_record {
# --------------------------------------------------------
# Builds a record based on the config information.
#

if (($rec{'Status'} eq 'active') || $per_admin) {
my (%rec) = @_;
my ($output, $field);

$output = "<p><table border=0 width=450>";
foreach $field (@db_cols) {
next if ($db_form_len{$field} == -1);
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%><$font>$rec{$field}</font></td></tr>
~;
}
$output .= "</table></p>\n";
return $output;
}
}
However, I'm still getting a record returned for which field 2 (named Status in default.cfg)=inactive

What did I miss?
Does it have to be Yes|No rather than active|inactive?
Thanks.

Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
active should be set to whatever value the field recieves when it is infact validated.

Also note that it will also display if the user has admin permissions (... || $per_admin), this is so the record is still available to an admin for validating.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Thanks again, but still no go.

When validated, the second field named "Status" changes from "inactive" to "active"

However, with the code you supplied above inserted into db.cgi, a search still returns a record which has Status=inactive (is it because 'active' is part of in'active'?)

I tried the search form with uid=default... I have the cfg so that you do not need to login to search, but I don't think this should change things?

Thanks again.

Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Instead of putting the "if" in db.cgi, try it in html.pl (inside sub html_record). This way, it should cover you regardless of wether you use auto-generate or not.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Thanks for being so patient with me - I didn't read your initial advice closely enough as I was still thinking of html.pl as a template only.

It now works like a charm and no inactive records show... except that if someone searches and the only result is an inactive record, the search still says:
Your search returned 1 matches. I wonder if there is an easy way to get rid of this if no "active" matches are found.

(or if it is easier, I wonder if I could only display the number of matches if more than 10 records were found. It's just confusing if it says 1 match found and the page is blank.)

Thanks again!

Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Oops - I spoke too soon.
Placing this in html.pl keeps the inactive records from showing, but it does not show the active records either. I was so excited that the inactive records for my test search were not showing, that I didn't catch that no results were showing. There are 170 records for which Status=active

Hmmm...
Code:
sub html_record {
# --------------------------------------------------------

# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.


if (($rec{'Status'} eq 'active') || $per_admin) {

my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

print qq|
<center>
<TABLE Width="85%" CELLPADDING=3 CELLSPACING=0 BORDER=0 BGCOLOR="#ffffff">
<TR><TD><font face="Arial, Veranda, Helvetica" size="+1">$rec{'Title'}</Font></TD></TR>

<TR><TD><font face="Times, Times Roman, Serif" size="-1">$rec{'Description'}</Font></TD></TR>

<TR><TD><font face="Times, Times Roman, Serif" size="-1" color="#333333"><A HREF="$rec{'URL'}">$rec{'URL'}</A></Font></TD></TR>
</TABLE>

|;
}
}
and the field from default.cfg
Code:
Status => [1, 'alpha', 0, 50, 1, '', 'active|inactive'],
Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Move the if statement down one line (under my (%rec) = @_;)

Sorry, my fault Crazy

As for the "Returned X Hits", this is one of the problems that can arise from doing it this way... Without hacking into the query sub-routine, you may just have to find a work-around.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Thank you for all your help :)
Works great!

Quote Reply
Re: how to search for keywords, only if field2=active? In reply to
Looks like you have it working, but I did want to mention that I remember seeing something similiar to where there was a problem with searching in a field such as:

male / female to where it was necessary to include ww=1 to be sure that it matched the whole field.

Otherwise it was picking up the "male" portion from both options. Hope this makes sense Smile



Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/