Gossamer Forum
Home : Products : DBMan : Customization :

search option? (duplicates)

Quote Reply
search option? (duplicates)
I have been searching the forum here, and have not found the answer, so I'll post the question....Unsure

Is there a way to have a special search option displayed which will not display duplicate records (fields other than the keyfield are often dupes). In my example, I have a list of people and their addresses. I want only to show the cities they live in, and if two people live in one city, only show that city one time. There are other times (like when modifying records) which I do want to be able to list all records regardless of dupes, so hacking up the query function in db.cgi is probably not my solution.

Thanks

Wes
Quote Reply
Re: [kd4rdb] search option? (duplicates) In reply to
Are you referring to a search form in which you only display single values as an option to choose from?

If so you can create a custom search form and use for example:

<TR><TD><$font>City:</FONT></TD><TD>|; print &build_select_field_from_db("City",$rec{'City'}); print qq|</TD></TR>

If you are talking about the output of display for example in the short display of records you can use for example:

|;
unless ($seen{$rec{'City'}}) {
print qq|$rec{'City'}|; $seen{$rec{'City'}} = 1;}
print qq|

for each field that would contain duplicates. This will display only the first City and then all the other listings within that city would only display the other fields in the results.

Add this line to the beginning of your html.pl, *before* any of the subroutines are called Code:

my %seen; # used for filtering out duplicate field values in html_record

If that doesn't make sense you may want to search the forum or FAQ for "unless ($seen{" to find the original thread.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/

Last edited by:

LoisC: Dec 10, 2002, 1:24 PM
Quote Reply
Re: [LoisC] search option? (duplicates) In reply to
Thanks... you hit the nail on the head.... and answered my next question too... how to count how many within each city.

WesSly
Quote Reply
Re: [LoisC] search option? (duplicates) In reply to
sub record_count {
my (%rec) = @_;
$seen{$rec{'City'}}++;
}

*********************************************

snip

*********************************************

highlights from "html_view_success"

# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
&record_count (&array_to_hash($_, @hits));
}
for (0 .. $numhits - 1) {
&html_record (&array_to_hash($_, @hits));
}
if ($db_next_hits) {
print "<$font>Pages: $db_next_hits</font>";
}


I decided to use your array idea, but instead of simply setting an array element to one, I thought I'd run thru the array contained @hits one time BEFORE actually displaying the results in html_record sub. The thought here is that I want to add up all the occurances of a particular city, then be able to print the city and the number of hits at a later time. Then I'll set the array element to a particular value like -1 that can't occur in normal processing, and test for -1 before deciding to print a record or not from the html_record sub.

Problem is, when I run the first "for...next" loop to do my initial count, it seems to gobble up the hits and nothing gets displayed when I run the 2nd "for...next" loop to actually display the data.

What am I missing? TIA

Wes