Gossamer Forum
Home : Products : DBMan : Customization :

Alphabetical Category Search and More

(Page 1 of 2)
> >
Quote Reply
Alphabetical Category Search and More
Hi,
Please forgive if this topic has been discussed. I've searched and came close, but no go. If it has, just point me to it, please.
I am building a business directory site that I want people to be able to search by category as well as by city.
I've gotten the browse mod that Eliot posted so that it will list all categories in the database with the number of listings for that category. But, since this will become a long list, and noone wants to scroll from a to z, I'd like to Break these down. I was thinking of an a to z list that would take them to a page of all categories. At that point thaey could click on a category and bring up the listings.
The second way to search is by city. I'm covering three counties with a total of 103 cities. I know I can use the browse mentioned above to list all cities. I'd like to break this down by county and have a three column table with the name of the county at the top and then the cities listed.
I hope I've made myself clear enough that someone can understand me.(After reading it over, it seems like I'm rambling.)
Thanks
Quote Reply
Re: Alphabetical Category Search and More In reply to
I don't know. Could you give me the link that you are using?


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
I got it.
I mentioned the one bracket missing. Well, I had it in the wrong place.
It was:

++$count{$fields[$fieldnum]};
}
close DB;
}

Looks like that closed the database prematurely.
It should have been:

++$count{$fields[$fieldnum]};

close DB;
}
}

Anyway, I believe it's working now. I sure do appreciate your help. Until the next stumbling block,
Thanks
Quote Reply
Re: Alphabetical Category Search and More In reply to
I'm not sure why that works, but, if it does, that's all that matters! Smile

You're welcome.


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
Can you post the code you used for the categories? There are a number of versions of that mod floating around and I'd like to know which one you're dealing with. At least find the thread with the code in it, so we're on the same page. Smile


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
Yes,
Heres the code that I'm using. I believe I also had to add an else statement in the db.cgi for it to work. Played around with it so much, it's hard to remember.
Thanks
sub html_browse_cat {
# --------------------------------------------------------
# Browse Academic Areas
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Area field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
close DB;
$page_title = "Main Menu";
&html_page_top;

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Browse Categories</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<table bgcolor="#FFFFFF" cellpadding=2 cellspacing=0 width=600 align=center valign=top>
<tr><td>

<$font_title>
<center>
<b>Browse Categories</b></center>
</font>
<p>
<$font>
<p>
|;
foreach $field (sort @selectfields) {
if ($sfield eq "") {
print qq| |;
}
if ($sfield = &urlencode($field)) {
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield">
$field</a>:</font><font color="ff0000">($count{$field})</font><BR>|;
}
}
print qq|</font> |;

&html_footer;
&html_page_bottom;


}
Quote Reply
Re: Alphabetical Category Search and More In reply to
Thanks. Smile

You will have a previous page with the alphabet, each with a link to the browse_category routine. Right? (I don't know what your link is to get to this page.)

Add &start=letter to each of the links --
for the A link, add &start=A
for the B link, add &start=B
etc.

Then, in your code, change

Code:
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};

to

Code:
if ($fields[$fieldnum] =~ /^$in{'start'}/i) {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}


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







[This message has been edited by JPDeni (edited September 30, 1999).]
Quote Reply
Re: Alphabetical Category Search and More In reply to
OK,
After modifying the html.pl I get an error. It just needed a clossing bracket. No problem. But, it will only list A categories no matter what letter I use after &start=?
Even if I dont use the &start at all it only shows A categories.
What did I do wrong?(grin)
Quote Reply
Re: Alphabetical Category Search and More In reply to
OK,
Seems like the first part of the problem is fixed. Do you have any idea what to do about the second part of my original post?
Thanks
Quote Reply
Re: Alphabetical Category Search and More In reply to
Ok here goes.
Off the main page of my site I have a Browse listings by city. When clicked it takes them to the city page you helped me with. It shows every city sorted by county with the number of listings. Right now, when you click on a link to a city, it brings up all listings for that city. This is a business directory, and I need to be able to break it down by category. So, instead of getting all listings for that city, I'd like to get a listing of all categories for that city with the count beside that.
So it would go: Browse by city - List all cities sorted by county - click on one of the cities - list of all categories in that city - click on category - bring up the listings for that category in that city.
Let me know if that helps.
Quote Reply
Re: Alphabetical Category Search and More In reply to
Thanks Alot. Works great. The only thing left to do is get the number count placed beside each city. I'll keep at it, but thank you very much.
Quote Reply
Re: Alphabetical Category Search and More In reply to
Hey, I even got the numbers working. I believe everything is now working the way I want. I'll play around with it. Thanks again for all your help.
Quote Reply
Re: Alphabetical Category Search and More In reply to
Oops,
I found something. For you I believe it would be quite simple. When you click on one of the cities, it brings up all listings for that city. What would I have to change to make it list the categories for that city instead of the listings?
Thanks
Quote Reply
Re: Alphabetical Category Search and More In reply to
Well,
I thought I could get this. But I'm missing something basic. Right now we have it listing all cities per county. What would it take to get it to list all categories in a city that is selectable, Like we did with the alphabetical category list. Any ideas.
Thanks
Quote Reply
Re: Alphabetical Category Search and More In reply to
I think I need for you to give me an example of what you want.


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
In db.cgi, sub main, add

Code:
elsif ($in{'browse_cities'}) { if ($per_view) { &html_browse_cities; } else { &html_unauth; } }

In sub html_footer (or wherever you want the link to print out, add

Code:
print qq!| <A HREF="$db_script_link_url&browse_cities=1">View</A> ! if ($per_view);

Add a new subroutine to html.pl:

Code:
sub html_browse_cities {
# --------------------------------------------------------
$County_number = 5;
$City_number = 6;

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$City_number], @{$Cities{$fields[$County_number]}})) {
push (@{$Cities{$fields[$County_number]}}, $fields[$City_number]);
}
if (!(grep $_ eq $fields[$County_number], @Counties)) {
push (@Counties, $fields[$County_number]);
}
}
close DB;

&html_page_top;

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Browse Cities</title>
</head>

<body bgcolor="#FFFFFF">
<center>
<table bgcolor="#FFFFFF" cellpadding=2 cellspacing=0 width=600 align=center valign=top>
<tr><td>
<$font_title>
<center>
<b>Browse Categories</b></center>
</font>
<p>
<$font>
|;
print "<table><tr valign=top>";
foreach $County (sort @Counties) {
print "<td>$County</td>";
}
print "</tr><tr>";
foreach $County (sort @Counties) {
print "<td>";
$county_url=&urlencode($County);
foreach $City (sort @{$Cities{$County}}) {
$city_url = &urlencode($City);
print qq|<a href="$db_script_link_url&view_records=1&City=$city_url&County=$county_url">$City</a><BR>|;
}
print "</td>";
}
print "</tr></table>";

print qq|</font>|;

&html_footer;
&html_page_bottom;

}

I haven't tested this directly, but it's put together from different things that have worked before and I did check it for syntax errors, so it should work.

You will need to set the variables $County_number and $City_number to match the number of the matching fields in your database. Also, be sure to change the field names City and County in the link if your field names are different.

You will notice that the script prints out a 3 x 2 cell -- 3 columns and 2 rows -- with the county names in the first row and the city names in the second row. It was too confusing to try to figure out how to put the city names each in their own cell.


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
Ah. You want a multi-tierd approach. And a count.

The count is a little easier, so I'll start with that.

In sub html_browse_cities, after

Code:
@fields = &split_decode ($line);

add

Code:
$counter_name = $fields[$County_number] . $fields[$City_number];
++$count{$counter_name};

and after

Code:
$city_url = &urlencode($City);

add

Code:
$counter_name = $County . $City;

Change

Code:
print qq|<a href="$db_script_link_url&view_records=1&City=$city_url&County=$county_url">$City</a><BR>|;

to

Code:
print qq|<a href="$db_script_link_url&view_records=1&City=$city_url&County=$county_url">$City</a>
($count{$counter_name})<BR>|;

Make these changes first, to make sure the counter works.

If that's going okay, then make the following changes:

In sub html_browse_cat, right at the beginning, add

Code:
$County_number = 5;
$City_number = 6;

again, changing the numbers to match the appropriate field numbers.

Change

Code:
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};

to

Code:
@fields = &split_decode ($line);
if ($in{'City'} && $in{'County'}) {
if (($in{'City'} eq $fields[$City_number]) && ($in{'County'} eq $fields[$County_number])) {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
}
else {
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}

Then go back to sub html_browse_cities and change

Code:
print qq|<a href="$db_script_link_url&view_records=1&City=$city_url&County=$county_url">$City</a>
($count{$counter_name})<BR>|;

to

Code:
print qq|<a href="$db_script_link_url&browse_cat=1&City=$city_url&County=$county_url">$City</a>
($count{$counter_name})<BR>|;

I don't know what your flag is to get to the browse category page, so if it isn't browse_cat, change it to match.


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





Quote Reply
Re: Alphabetical Category Search and More In reply to
Hello again.
I had a heck of a time getting that one to work last night. Gave up, got up this morning, and no problem. Guess I'm not a night person. Smile Anyway, were getting real close. It now sorts it correctly until you go to view the records. If I browse by city, it gives me every city sorted by county. Perfect. If I click on a city, it brings up every category for that city. Perfect. But when I click on a category, it lists all records under that category. Not perfect. It should only show records in that category in that city in that county. What do I need to do to push the city and county information.
It works right if I type it in the address bar with all my variables, but I can't seem to get it with the script. I put this online, so if it helps you can check it out at www.tricobiz.com. Follow the links for browse by city and you'll see what I mean.
We also lost the browse by category alphabetical. But like you say, one problem at a time.
Quote Reply
Re: Alphabetical Category Search and More In reply to
Sorry. I forgot about one other thing. In sub html_browse_cat, change

Code:
foreach $field (sort @selectfields) {
if ($sfield eq "") {
print qq| |;
}
if ($sfield = &urlencode($field)) {
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield">
$field</a>:</font><font color="ff0000">($count{$field})</font><BR>|;
}
}

to

Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
if ($in{'City'} && $in{'County'}) {
$county_url=&urlencode($in{'County'});
$city_url = &urlencode($in{'City'});
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield
&City=$city_url&County=$county_url">$field</a>:</font>
<font color="ff0000">($count{$field})</font><BR>|;
}
else {
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield">
$field</a>:</font><font color="ff0000">($count{$field})</font><BR>|;
}
}

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





Quote Reply
Re: Alphabetical Category Search and More In reply to
Carol,
I believe that everything is working the way I want it to. I wanted to let you know you are one fantastic person. To put up with all the questions and help as much as you do, I wanted to send you a sincere thank you. You have certainly saved me alot of grey hairs.
God Bless,
Rick Roberson
Quote Reply
Re: Alphabetical Category Search and More In reply to
Carol,
I'm really sorry to bother you again. Seems the browse alpha is still not working.
Here's what I have:
sub html_browse_alpha {
# --------------------------------------------------------
# Browse By Alphabetical Order
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Area field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
if ($fields[$fieldnum] =~ /^$in{'start'}/i) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};

close DB;
}
}
$page_title = "Browse Categories By Alphabetical Order";
&html_page_top;

&html_print_headers;
print qq|
<center>
<table bgcolor="#FFFFFF" cellpadding=2 cellspacing=0 width=600 align=center valign=top>
<tr><td>

<$font_title>
<center>
<b>Browse Categories By Alphabetical Order</b></center>
</font>
<p>
<$font>
<p>
|;
foreach $field (sort @selectfields) {
if ($sfield eq "") {
print qq| |;
}
if ($sfield = &urlencode($field)) {
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield">
$field</a>:</font><font color="ff0000">($count{$field})</font><BR>|;
}
}
print qq|</font> |;

&html_footer;
&html_page_bottom;


}

With the changes we made to browse city and category, do we need to change this as well?
Quote Reply
Re: Alphabetical Category Search and More In reply to
 
Code:
sub html_browse_alpha {
# --------------------------------------------------------
# Browse By Alphabetical Order
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Area field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
if ($fields[$fieldnum] =~ /^$in{'start'}/i) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum]};
}
}
close DB;


$page_title = "Browse Categories By Alphabetical Order";
&html_page_top;

&html_print_headers;
print qq|
<center>
<table bgcolor="#FFFFFF" cellpadding=2 cellspacing=0 width=600 align=center valign=top>
<tr><td>

<$font_title>
<center>
<b>Browse Categories By Alphabetical Order</b></center></font>
<p>|;

foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&view_records=1&Category=$sfield">
$field</a>:</font><font color="ff0000">($count{$field})</font><BR>|;
}
print qq|</font> |;

&html_footer;
&html_page_bottom;

}

Maybe this will work. If not, please be a little more specific about what doesn't work.



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





Quote Reply
Re: Alphabetical Category Search and More In reply to
JPD,
Thank you for your many programming attributes. This mod is working for me at the admin level and I would like it to work at the user id level as well. This is how I have it working now; a user who has already "Scheduled" an appointment clicks a &html_browse_month routine which allows for a month selection, which looks like this
<a href="$db_script_link_url&BookMon=Oct&browse_appt=1"><$font2>Oct</a>, for the month of "Oct". When a month is selected, a new page is displayed, which browses by date and shows the number of appointments scheduled on that date (1 to 31 until I can figure out Feb) with a link to the view_records sub routine. At the same time I call another browse subroutine for the "Times" an appointment was scheduled by date. Also, I call another subroutine, which browses status levels of the appointments and provides a count on status levels. Following are the three browsing sub routine called for the scheduled appointment by month listing;

sub html_browse_dates {
# --------------------------------------------------------
$BookDate_number = 199;
$ConInqStat_number = 162;
$BookMon_number = 195;

for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "BookDate" ) {
$fieldnum = $i; $found = 1;
last;
}
}

sub html_browse_times {
# --------------------------------------------------------
$BookDate_number = 199;
$ConAppTime_number = 160;
$ConInqStat_number = 162;
$BookMon_number = 195;

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$BookMon_number] =~ /^$in{'BookMon'}/i) {
$counter_name2 = $fields[$ConInqStat_number];
$counter_name = $fields[$BookDate_number] . $fields[$ConAppTime_number];
++$count2{$counter_name2};
if ($fields[$ConInqStat_number] eq "Scheduled"){
++$count{$counter_name};
}
if (!(grep $_ eq $fields[$ConAppTime_number], @{$Times{$fields[$BookDate_number]}})) {
push (@{$Times{$fields[$BookDate_number]}}, $fields[$ConAppTime_number]);
}
if (!(grep $_ eq $fields[$BookDate_number], @Dates)) {
push (@Dates, $fields[$BookDate_number]);
}
}
}
close DB;
print "<table border=1><tr valign=top>";
foreach $BookDate (sort @Dates) {
print "<td><$font>$BookDate</font></td>";
}
print "</tr><tr>";
foreach $BookDate (sort @Dates) {
print "<td valign=top>";
$BookDate_url=&urlencode($BookDate);
foreach $ConAppTime (sort @{$Times{$BookDate}}) {
$ConAppTime_url = &urlencode($ConAppTime);
$counter_name = $BookDate . $ConAppTime;
print qq|<$font0><a href="$db_script_link_url&view_records=1&ConInqStat=Scheduled&sb=160&ConAppTime=$ConAppTime_url&BookDate=$BookDate_url">$ConAppTime</a >($count{$counter_name})</font><BR>|;
}
print "</td>";
}
print "</tr></table>";
print qq|</font>|;
}

sub html_browse_status {
# --------------------------------------------------------
$BookDate_number = 199;
$ConInqStat_number = 162;
$BookMon_number = 195;

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$BookMon_number] =~ /^$in{'BookMon'}/i) {
$counter_name = $fields[$BookDate_number] . $fields[$ConInqStat_number];
++$count{$counter_name};
if (!(grep $_ eq $fields[$ConInqStat_number], @{$Status{$fields[$BookDate_number]}})) {
push (@{$Status{$fields[$BookDate_number]}}, $fields[$ConInqStat_number]);
}
if (!(grep $_ eq $fields[$BookDate_number], @Dates)) {
push (@Dates, $fields[$BookDate_number]);
}
}
}
close DB;
print "<table border=1><tr valign=top>";
foreach $BookDate (sort @Dates) {
print "<td><$font>$BookDate</font></td>";
}
print "</tr><tr>";
foreach $BookDate (sort @Dates) {
print "<td valign=top>";
$BookDate_url=&urlencode($BookDate);
foreach $ConInqStat (sort @{$Status{$BookDate}}) {
$ConInqStat_url = &urlencode($ConInqStat);
$counter_name = $BookDate . $ConInqStat;
print qq|<$font0><a href="$db_script_link_url&view_records=1&sb=160&ConInqStat=$ConInqStat_url&BookDate=$BookDate_url">$ConInqStat</a>($count{$counter_ name})</font><BR>|;
}
print "</td>";
}
print "</tr></table></font>";
}

if ($found) {
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason
: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$BookMon_number] =~ /^$in{'BookMon'}/i) {
$counter_name3 = $fields[$ConInqStat_number];
++$count3{$counter_name3};
if ($fields[$ConInqStat_number] eq "Scheduled"){
++$count{$fields[$fieldnum]};
}
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
}
close DB;
@options = split (/\,/, $db_select_fields{'BookDate'});
foreach $option (sort @options) {
$date_link=&urlencode($option);
unless ($count{$option}) {
$count{$option} = '0';
}
print qq|
<a href="$db_script_link_url&ConInqStat=Scheduled&sb=160&BookDate=$date_link&view_records=1"><$font>$option</a>
($count{$option}) </font>
|;
}
}
}

After all that, when logged in as a user with view/mod own only permisions, when I hit the month link the next page displays all records instead of only the user records.

Also, it would be really nice if I could loop the browse_times sub so that it lists maybe five or so days horizontally, creates a new row and then lists 5 or so days again and so on; instead of listing all 31 days in one row. This would also apply to the browse_status subroutine.

Many thanks in advance
Quote Reply
Re: Alphabetical Category Search and More In reply to
Hi, I don't know if this is a more tedious way to do this, but I list my resources by letter on a few of my DBMAN pages. For example http://www.lib.lsu.edu/cgi-bin/dbman/dbman/db.cgi?db=ejournals&uid=default

I made an additional field titled "Letter" and assigned each resource the letter it begins with for the field.

The outut directive for the letters still teels it to sort by title, but it has an additional &Letter=M (for example).

Will that do what you want?
Quote Reply
Re: Alphabetical Category Search and More In reply to
sigrid,
Thank you for the input WOW LSU is lucky to know you. I am not the best at perl so much of this is a cut and paste deal. Nevertheless, I am not sure what you mean by assigning each letter to a resource? It looks like your "Letter" assignment is like my "BookMon" above.

I would like to see how you are able to pick in #1. broad and narrow searches.

Thanks in advance
> >