Gossamer Forum
Home : Products : DBMan : Installation :

Grouped short short long display

Quote Reply
Grouped short short long display
This one may be a bit tricky.
My search is from a static page and contains 3 fields, category(dropdown list), make(text) and model(text).
What I need to do is this.
If a user searches by category, then a grouped short list by Make would be returned as clickable urls.
They then pick from the Make list to continue there search, which would return a grouped short list by Model.
If they picked from the Model shoth list, all long records by model would be returned.
It's a long way of searching for categoy/make/model.
They would have to be able to do regular searches as well, but the results would be returned as per above, ie if they left category blank and searched by make, it would return the short list by model.
It would also be good to return the number in each group, ie apples(10), banans(51) etc.
If we can get this to work I may even add a search by country, country/category/make/model.
I hope this isn't hard to understand.
Thanks
Bob
Quote Reply
Re: Grouped short short long display In reply to
I understand what you want and there are some threads here where this sort of thing has been discussed.

I'm really not up to writing code today, though. I'll have to get back to you.


------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
I knew there was another thread I needed to respond to, but I couldn't remember where it was. Sorry 'bout that. Sunday was a bad day.

Could you give me the code you have come up with so far, if any?

Do you only want to list the Categories, Makes and Models that are currently in the database?


------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
Ok i'm stuck, I realy need some help on this.
I realy don't know how to return the $ENV{'QUERY_STRING'} back into another short display, or terminate the short displays after 3 or 4 deep into a long display.
I've searched the BBS so many times. If there is a post on this that I have missed, maybe someone knows where it is.
For some reason i've posted this in Install, instead of Discussion. oops.
thanks
Bob
Quote Reply
Re: Grouped short short long display In reply to
Bad days are no fun. Thank god we have more good ones than bad.
I havn't make a start on this with any code. I looked at this for hours, but drew a blank.
Yes I do need to list everything in the database, It's just like a normal search using tiered grouped short displayes before the long.
A search by category alone would return a grouped short list by make, as per the short long mod which I am using. The search then would be by make, which would return a short list by model, ie category/make/model. The search by model would return a normal long list.
Of course they would have the option to search on any or all fields.
So you would need to return two short urls, the first with $rec{make}, the second with $rec{model}.
But I have no idea how to do this.
thanks
Bob

[This message has been edited by lanerj (edited August 25, 1999).]
Quote Reply
Re: Grouped short short long display In reply to
You're absolutely right about the good days and bad days. Not sure why Sunday was so bad. My brain just wouldn't function and I spent most of the day watching reruns of "I've Got a Secret" on the Game Show Network. Smile

I'll be back. I promise this time. Smile I just need to work out some things offline, because it's a little tricky. I am going to be leaving this afternoon and I'll probably be gone through the evening. With any luck I'll get your things done before I leave. If not, I'll post it tonight.


------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
Okay, Bob. I think I have something for you.

This assumes that, when someone does a search, they will have selected a Category, Make or Model.

There are a couple of notes in the code. Be sure to read them and set things accordingly. Also, I'm assuming your field names are Category, Make and Model. If they're not, you'll have to change the variables to match your field names.

Here goes.

First, replace sub html_view_success with the following:

Code:
sub html_view_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.
#

my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
$in{'nh'} ? ($nh = $in{'nh'}) : ($nh = 1);

$page_title = "Search Results";
&html_page_top;

if ($in{'Model'}) {

# Go through each hit and convert the array to hash and send to
# html_record for printing.
if (($db_total_hits == 1) | | ($maxhits == 1)) {
&html_record_long(&array_to_hash(0, @hits));
}

else {
print qq|<p><$font>Your search returned <b>$db_total_hits</b> matches.</font>|;
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
$i = 1;
print "<table>";
for (0 .. $numhits - 1) {
print "<tr>";
&html_record (&array_to_hash($_, @hits));
print "</tr>";
++$i;
}
print "</table>";
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>";}
}
}
elsif ($in{'Make'}) {
&list_models;
}
elsif ($in{'Category'}) {
&list_makes;
}
&html_footer;
&html_page_bottom;
}

Add the following two subroutines to the html.pl file:

Code:
sub list_models {
# --------------------------------------------------------

open (DB, "<$db_file_name") or
&cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

$model_fieldnum = 4; # Change this to match the field number of your model field
$make_fieldnum = 5; # Change this to match the field number of your make field

foreach $line (@lines) {
chomp($line);
@data = &split_decode($line);
if ($data[$make_fieldnum] eq $in{'Make'}) {
if (!(grep $_ eq $data[$model_fieldnum], @model_list)) {
push (@model_list, $data[$model_fieldnum]);
}
}
}
foreach $model (@model_list) {
$model_link = &urlencode($model);
$make_link = &urlencode($in{'Make'});
print qq|<a href="$db_script_link_url&Make=$make_link&Model=$model_link&view_records=1">$model</a><BR>|;
}

}

Code:
sub list_makes {
# --------------------------------------------------------

open (DB, "<$db_file_name") or
&cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

$make_fieldnum = 5; # Change this to match the field number of your model field
$category_fieldnum = 3; # Change this to match the field number of your make field

foreach $line (@lines) {
chomp($line);
@data = &split_decode($line);
if ($data[$category_fieldnum] eq $in{'Category'}) {
if (!(grep $_ eq $data[$make_fieldnum], @make_list)) {
push (@make_list, $data[$make_fieldnum]);
}
}
}
foreach $make (@make_list) {
$make_link = &urlencode($make);
$category_link = &urlencode($in{'Category'});
print qq|<a href="$db_script_link_url&Make=$make_link&Category=$category_link&view_records=1">$model</a><BR>|;
}

}

Add the following subroutine to db.cgi

Code:
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
return $toencode;
}

I did check it for syntax errors, but haven't tested it anywhere. I hope this is what you want.


------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
Thanks JPD this seems to work fine, although I havn't got the time at the moment to fully test it, got to go and earn a $, but I'll get back to you if somthing is amiss.
Maybe you can answer this, or have come across it before.
I've tried the above mod on from a static html search, but the Make field seems to be case sensitive, where as the Model field isn't. Category is hard wired into a dropdown, so that's no problem.
If I do a search by Make ie "fender" (recs are entered as "Fender"), I don't get anything, not even an error, but If I do a search by Make/Model, ie "fender" "STRAT", it will work.
Gategory and Make won't work either ie "Guitars" "fender". But adding the Model field to the search, in any case, will work.
"Fender" will work, so it seems that the make field is case sensitive...strange one.
thanks again
Bob
Quote Reply
Re: Grouped short short long display In reply to
That's really odd. My suspicion is that there's something else going on here, but I'm not sure what it is. The best thing to do would be to make sure your case is the same.

(I'm glad you mentioned what product you were dealing with. We've had so many people setting up databases for cars, that's what I thought yours was, too. Smile Got any nice acoustics?)



------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
Cars, when they get old all they do is rust.
Guitars are like fine wine and good women, the more they mature the better they get.
I am having some problems with this.
The main one is that i've lost my List all, and view recs from within dbman.
I,ve go Automatic view/modify search mod installed, for those without admin permission, but the view link won't list, it comes up blank.
You can search in admin via the search form, but no list all.
Default search from the static page works.
I,ve been through and cleaned up a few stray html tags, which were messing things up, but I carn't seem to find the problem.
I havn't any major mod in sub_query, except for the the change of permissions mod to allow default and auth_view_own.
Every thing worked fine untill I installed the above mod, although I was not searching fron a static page then.
What ever is wrong, may also be the cause of my search being case sensite on certian fields.
thanks
Bob
Quote Reply
Re: Grouped short short long display In reply to
I guess I didn't take "List All" into account and assumed that something would be selected.

Let me see where I can add some code to fix this.

Here's someplace that might make it work. In sub html_view_success, change

Code:
if ($in{'Model'}) {

to

Code:
if ($in{'Model'} or $in{$db_key}) {

I still don't know what could make things case sensitive on certain fields.


------------------
JPD





Quote Reply
Re: Grouped short short long display In reply to
Thanks JPD that fixed it, I think I'll get off install and back onto discussion.
Thanks
Bob