Gossamer Forum
Home : Products : DBMan : Customization :

Alphabetic listing

Quote Reply
Alphabetic listing
Hello All,

I am new to DBMan but I have it setup and running. I am interested in being able to display quick links to each of the letters of the alphabet which when clicked on would take the user to the set of records beginning with that letter as specified by field which in this case is Title.

I did a search on "alphabet" in this forum and found a very relavent link :
www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/001234.html

A gentleman named Eliot provided codes which I thought would do exactly what I wanted - he also provided example links which displayed exactly what I wanted. I tried following the directions explicitly but unfortunately I am unable to get it to work. Obviously I have messed something up.

I have gathered from other posts, that when requesting help it is good to provide access to pertinent files so here they are :
default.cfg - www.webmerchantsoftware.com/default.cfg.txt

html.pl - www.webmerchantsoftware.com/html.pl.txt

Test the database - www.webmerchantsoftware.com/cgi-bin/dbman/db.cgi

The basic problem as you will see is that no links to the letters of the alphabet ever get printed out. Any assistance or guidance would be greatly appreciated.


------------------
Easy does it,
Bear

[This message has been edited by Bearwithme (edited May 07, 2000).]

[This message has been edited by Bearwithme (edited May 07, 2000).]
Quote Reply
Re: Alphabetic listing In reply to
Bear,

What I would think about doing is create an admin-only hidden field...in this field you'd simple enter a letter...a-z...then you could setup links as a default user to search based on the contents of that field...that MIGHT do the trick.

Chris

[This message has been edited by TWTCommish (edited May 07, 2000).]
Quote Reply
Re: Alphabetic listing In reply to
Very good! Someone who actually reads the forum!!!! Smile

I looked at your html.pl file, but I didn't see the code for the alphabetical listing. What file did you put it in?

It needs to go into the html.pl file. (Possibly I didn't make that clear enough in the other thread.)


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






Quote Reply
Re: Alphabetic listing In reply to
Hello JPdeni,
Thank you for responding.

Quote:
I looked at your html.pl file, but I didn't see the code for the alphabetical listing. What file did you put it in?

But it is in there in a sub routine called sub browse_cat right after sub html_home just as the instructions in the original thread instructed. The working web site examples that Eliot provided are exactly what I need to accomplish, however the example code I have been unable to get to work due to some oversight on my part no doubt.

I'm hoping that some kind soul looking over my code files will be able to see where I went wrong. I'd be so excited to actually get this working as I've literally spent the entire weekend tearing my hair out trying to make it so. Thank you so much.


------------------
Easy does it,
Bear


[This message has been edited by Bearwithme (edited May 07, 2000).]
Quote Reply
Re: Alphabetic listing In reply to
The code for sub html_browse_cat from your html.pl file is as follows (with a little change in formatting):

Code:
sub html_browse_cat {
# --------------------------------------------------------
# Browse Categories.
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Title") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Title 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 ($fields[25] eq "Yes") {
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}
}
}
close DB;
&html_print_headers;
print qq|
<html> <head> <title>$html_title: Browse Categories</title></head>
<body bgcolor="#FFFFFF">
<center>
<table border=0 bgcolor="#FFFFFF" cellpadding=2 cellspacing=0 width="80%" align=center valign=top>
<tr><td>
<p>
<$font_title><b>
<A HREF="$db_script_link_url">$html_title</a> : Browse Categories</b></font>
<P><$font>
<b>List of Categories:</b>
|;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&vr=1&ID=*&Title=$sfield&sb=1&so=descend">$field</a>:</font>
<$smfont>(<font color="ff0000">$count{$field}</font> )</font><BR>|;
}
print qq|<P></font>|;
&html_footer;
print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}

The code in the thread to which you referred for printing out the alphabet is as follows:

Code:
print qq|<P><CENTER>|;
$i = 65;
while ( $i < 91 ) {
print qq| <A HREF="$db_script_link_url&company=%5E|;
print chr($i);
print qq|&re=on&view_records=1">[|;
print chr($i);
print qq|]</a>\n|;
++$i;
}
print qq|</CENTER></P>|;

I did not find the second code within the first one. I did a search in your file for

while ( $i < 91 ) {

and even just for

91 ) {

and I did not find it at all.

The code that Eliot posted in the thread does not print out the alphabet with links to do searching. It is a "browse category" mod.

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






Quote Reply
Re: Alphabetic listing In reply to
Hello JP,

Quote:
The code that Eliot posted in the thread does not print out the alphabet with links to do searching. It is a "browse category" mod.

Well then I guess I am totally confused, because in fact if you look at the original thread and in his response he says
Quote:
I already wrote codes for alphabetically listing awhile back. But here it goes again:
and again
Quote:
Replace FieldName with the name of the field that you would like to alphabetically list.
There is no mention of it being a "browse category mod" other than the sub is named browse_cat

And if you refer to this thread :
http://www.gossamer-threads.com/...m12/HTML/002829.html

he says
Quote:
Yep...Codes for this have been provided before. Search for "Alphabetical listing". I have this working in two web sites:

and provides 2 links which demonstrate exactly what I'm after.
http://vlib.anthrotech.com and
www.coco.cc.az.us/cgi-bin/directory/index.cgi?db=default&uid=default

I'm sorry if this is confusing, but the threads and responses appeared to be in fact exactly all about an alphabetical listing. I appreciate you posting your codes JPDeni but it appears they hard-code all 26 letters whether a record exists with that letter or not. If you look at Eliot's example site - the one at coco.cc.az.us his list has clickable letters for those letters where a record exists - the other ones X and Z I believe, are not clickable. If this is still confusing, I can respond better if you've had a chance to look this rambling mess over. Sorry JPDeni and thank you.

------------------
Easy does it,
Bear
Quote Reply
Re: Alphabetic listing In reply to
Point of clarification...

1) The codes that were posted (based on Codes JPDeni wrote a year ago) were for a category listing (Browse Category).

2) HOWEVER, I used two subs in that version of DBMAN...

1- with the complete HTML (header/footer codes) that showed the Alphabetical display.

2 - copy of that sub (without header/footer codes) that prints at the top of the search results via the sub html_search_success routine in the html.pl file.

Hope this makes better sense.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Alphabetic listing In reply to
Thanks Eliot,

Quote:
Point of clarification... 1) The codes that were posted (based on Codes JPDeni wrote a year ago) were for a category listing (Browse Category).

2) HOWEVER, I used two subs in that version of DBMAN...
1- with the complete HTML (header/footer codes) that showed the Alphabetical display. 2 - copy of that sub (without header/footer codes) that prints at the top of the search results via the sub html_search_success routine in the html.pl file.

I will try to figure it out...Am I right in assuming then that the working example at your coco.cc.az.us site prints the Alphabet letter listing dynamically - disabling letters which don't have a corresponding record for that letter?

After all this, I'm still not sure where to put what codes where to get the alphabet listing but I'm going to try and slug it out. Thanks



------------------
Easy does it,
Bear
Quote Reply
Re: Alphabetic listing In reply to
Possibly Eliot will be able to give you information about some other code he used. When I first wrote this code a long time ago, I hardcoded the letters that I knew would not have corresponding records.

Where you put the code depends on where you want the list to print out. If you want a separate page like Eliot has, you can create a subroutine. If you want it on the DBMan home page, you can put it in sub html_home.

I think I can come up with a routine that will dynamically create links for only the records that have corresponding letters.

Code:
$fieldnum = the number of the field you want to search by;
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
$letter = substr($fields[$fieldnum],0,1);
if (!(grep $_ eq $letter, @alphabet)) {
push (@alphabet, $letter);
}
}
print qq|<P><CENTER>|;
$i = 65;
while ( $i < 91 ) {
if (grep $_ eq chr($i), @alphabet) {
print qq| <A HREF="$db_script_link_url&db_cols[$fieldnum]=%5E|;
print chr($i);
print qq|&re=on&view_records=1">[|;
print chr($i);
print qq|]</a>\n|;
}
else {
print "[" . chr($i) . "]";
}
++$i;
}
print qq|</CENTER></P>|;

I just tested this on my home computer and it looks like it will work.

Now we just have to figure out where to put it. Smile


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








[This message has been edited by JPDeni (edited May 08, 2000).]
Quote Reply
Re: Alphabetic listing In reply to
JPDeni,

I have but 1 word for you - AWESOME!!!!! You certainly are JPDeni.

Code:
$fieldnum = the number of the field you want to search by;

I added :
Code:
$fieldnum = the number of the field you want to search by;
$fieldname = actual alpha string of the corresponding field above;

I changed this :
Code:
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
$letter = substr($fields[$fieldnum],0,1);
if (!(grep $_ eq $letter, @alphabet)) {
push (@alphabet, $letter);
}
}

to this :
Code:
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);
$letter = substr($fields[$fieldnum],0,1);
if (!(grep $_ eq $letter, @alphabet)) {
push (@alphabet, $letter);
}
}
close DB;

Then to print out the alphabetic links change this:
Code:
$i = 65;
while ( $i < 91 ) {
if (grep $_ eq chr($i), @alphabet) {
print qq| <A HREF="$db_script_link_url&db_cols[$fieldnum]=%5E|;
print chr($i);
print qq|&re=on&view_records=1">[|;
print chr($i);
print qq|]</a>\n|;
}
else {
print "[" . chr($i) . "]";
}
++$i;
}

to this:
Code:
$i = 65; while ( $i < 91 ) {
if (grep $_ eq chr($i), @alphabet) {
print qq| <A HREF="$db_script_link_url&sb=1&so=ascend&$fieldname=%5E|;
print chr($i);
print qq|&re=on&view_records=1">[|;
print chr($i);
print qq|]</a>\n|;
}
else {
print "[" . chr($i) . "]";
}
++$i;
}

Works perfectly JPDeni and you are truly amazing! To see it in action go to :
www.webmerchantsoftware.com/cgi-bin/dbman/db.cgi

Thanks again JP!!!!!

------------------
Easy does it,
Bear


[This message has been edited by Bearwithme (edited May 08, 2000).]

[This message has been edited by Bearwithme (edited May 08, 2000).]
Quote Reply
Re: Alphabetic listing In reply to
Very good. You caught my mistake (I forgot to close the file) and improved on the link.

Often (including this time), when I start answering someone, I don't think what they want can be done. As I type, sometimes the solution comes to me.

I'm pleased that it worked for you. (I did check it out and it works great! Smile )


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






Quote Reply
Re: Dynamic - Alphabetic listing In reply to
Could someone please help a real perl newbie. I found this code to be exactly what I am looking for. I would like viewers to be able to select a Letter to view a record sorted by user's names. However, for the life of me...I can't get the code by JDPeni or Bear to work. Obviously, I am not putting something in the right place. I tried to place the code in sub html_view_success in html.pl.

Could one of you please give me explicit instruction for adding this wonderful code. I would really appreciate it.

Schoolmarm's Lil Red School House & Academic Resource Net.
http://www.schoolmarm.org/
Quote Reply
Re: Dynamic - Alphabetic listing In reply to
I couldn't get that to work either. I finally just used the links below in html.pl to display a list of all members with a last name beginning with each letter.


<A HREF="$db_script_link_url&LastName=^A&mh=10&sb=1&so=ascend&cs=on&re=on&view_records=1">A</A>
<A HREF="$db_script_link_url&LastName=^B&mh=10&sb=1&so=ascend&cs=on&re=on&view_records=1">B</A>
<A HREF="$db_script_link_url&LastName=^C&mh=10&sb=1&so=ascend&cs=on&re=on&view_records=1">C</A>

etc... Good Luck.

Tom





Quote Reply
Re: Dynamic - Alphabetic listing In reply to
Thanks Tom for Responding to my plea. Your solution does indeed work...but doesn't give me the dynamic solution I was looking for. It would be really great to have only the actual letters of the alphabet which correspond to matching records visible to the user. This avoids the unwelcome Search Failed screen.

Some of my users are not internet savvy and I want to keep the program as unconfusing as possible for them. If they are doing a search using the form...then its not a surprise if a Failed Search shows. However, that screen coming up when the previous view was a nice display of records is rather ugly. Lol.

I guess I am just frustrated because I have made many modifications already to DBman and previously Links2 among other heavily modified cgi programs... But, I can't get this code to work when clearly other's have been able to do so. Aack, oh well, at least I can offer my users something.

Thanks Again,

Schoolmarm's Lil Red School House & Academic Resource Net.
http://www.schoolmarm.org/
Quote Reply
Re: Dynamic - Alphabetic listing In reply to
The modification are posted in the FAQ noted below in the section "Fields" with the thread titled:

Alphabetic listing

I have used this myself in several databases, and know that it works.

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