Gossamer Forum
Home : Products : DBMan : Customization :

Again - Alphabetical Listings

Quote Reply
Again - Alphabetical Listings
This seems to be something no one has worked out.

I would like the "list all" to take a field and list/sort alphabetically.

Has anyone figured this one out?? Would love to hear about it!

Also - Is there anyone using MySQL version? Is it available somewhere?? and is it hard to upgrade to MySQL??

Thanks

[This message has been edited by FLThiak (edited October 14, 1999).]
Quote Reply
Re: Again - Alphabetical Listings In reply to
I already wrote codes for alphabetically listing awhile back. But here it goes again:

Wink

1) Add the following codes to the elsif statements in the sub main routine in the db.cgi file:

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

2) Add the following codes to the top of a new sub-routine called sub html_browse_cat before the &html_print_headers; codes. This sub-routine can be a duplicate of sub html_home.

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "FieldName") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No FieldName 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[1] 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;

Replace FieldName with the name of the field that you would like to alphabetically list.

Then in the middle of the HTML codes in the sub-routine where you want the list to appear, use the following codes:

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&ID=*&sb=0&so=ascend&FieldName=$sfield">
$field</a>:</font> <$smfont>(<font color="ff0000">$count{$field}</font> )</font><BR>|;
}
}
print qq|

Change FieldName to the name of the field that you are listing.

3) To add a link to this listing, use the following:

Code:
<A HREF="$db_script_link_url&browse_cat=1">Browse Categories</a>

BTW: About the MySQL, one of my clients has purchased the SQL version and I am using MySQL on my server. To be perfectly, it is a pain to upgrade and also most if not all the mods written for the Standard DBMAN version will NOT work.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Again - Alphabetical Listings In reply to
Eliot,

In step 2 when you say, "Then in the middle of the HTML codes in the sub-routine where you want the list to appear, use the following codes"... What file/subroutine are you talking about? What would be a typical place to put this particular code?

Thanks,
-Jason
Quote Reply
Re: Again - Alphabetical Listings In reply to
What I meant was that in the middle of the new sub-routine after the header and intro text and before the footer and bottom of the file, you add the codes that I gave!

Like the following:

Code:
My Database: Browse Categories

|;
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&ID=*&sb=0&so=ascend&FieldName=$sfield">
$field</a>:</font> <$smfont>(<font color="ff0000">$count{$field}</font> )</font><BR>|;
}
}
print qq|

Footer Stuff

Hope this makes sense!

Wink

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Again - Alphabetical Listings In reply to
Eliot,

Sorry, it's not really clear. I'll try to explain where I am losing you.

You say I should add this "in the middle of the new sub-routine after the header and intro text and before the footer and bottom of the file" -- but the only new sub-routine that your instructions specified (html_browse_cat) didn't contain any HTML at all!

So should I create another new subroutine somewhere? If so, where, and in what file? And what do I need to call it? And what other places in the code do I need assure are calling it?

If I don't need to create another new subroutine, what file should I be looking at? In what existing subroutine is a good place to put this HTML code?

The response for the bonehead would be: "search for [[text string]] in file ____. After that, insert the following code." That would work for me. Smile
Quote Reply
Re: Again - Alphabetical Listings In reply to
YES...You create a NEW sub-routine. Read Step 2 more carefully:

Code:
sub html_browse_cat {
# --------------------------------------------------------
# Browse Categories.



for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "FieldName") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No FieldName 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">

|; &html_top_header; print qq|

<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=*&FieldName=$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>
|; &html_bottom_footer; print qq|
</center>
</body>
</html>
|;
}

Replace FieldName with the name of the field that you are listing.

I REALLY hope this helps.

Wink

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited October 16, 1999).]
Quote Reply
Re: Again - Alphabetical Listings In reply to
The original question was just about sorting the records in the "List All" link alphabetically.

To do that, add

Code:
&sb=#

to the "List All" link, replacing the # with the number of the field you want to sort by.

I have no experience with the SQL version of DBMan, but you can get it directly from Alex.

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





Quote Reply
Re: Again - Alphabetical Listings In reply to
I did everything above and it's not really what i was asking (as JP just wrote)..

what i was looking for was to sort a specified field alphabetically e.g fieldname 'last name' - i want to list all the names in the database by last name alphabetically.

..and then have links - [A][C] etc. on the top of the list and by clicking on the letter will list all names starting with A and all names starting with B etc.. basically it will search for all last names starting with the letter A or B or C ..

JP - could you go into more detail on your last post? thx

thanks
-frank
Quote Reply
Re: Again - Alphabetical Listings In reply to
Having the list of all names sorted alphabetically is not the same as creating links that will give you the names that begin with a certain letter.

If you want to return all the records in the database and have them sorted by a certain field, do this:

If your "Last Name" field is field 4 in your .cfg file, add

&sb=4

to the "List All" link, as follows:

Code:
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*&sb=4">List All</A> ! if ($per_view);

If you want to create links that will return only names that begin with a certain letter, that's a little more involved, but not too hard. A couple of questions first. Do you want these links to be on a static html page, or do you want the links to appear on a page within DBMan -- like the home page? Also, what is the actual *exact* name of the field you want to search by?


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





Quote Reply
Re: Again - Alphabetical Listings In reply to
the name of the field is 'company' and the field # is 11.

i don't really understand what you mean my 'static html page' - do you mean like Links that builds html pages?

I think it would be best to just have it within dbman as part of 'list all' - when the user clicks on 'list all' it will list all companies starting with [A] and i've already inserted the row [A][C][D] etc. in html_view_success below Your search returned 7 matches- these letters will be linked to search company names starting with the letter they click.

does this make sense?

here is an example: cgi.jobs.com/cgi-bin/employer?zoneid=-1&letter=A

thanks
-frank


[This message has been edited by FLThiak (edited October 17, 1999).]
Quote Reply
Re: Again - Alphabetical Listings In reply to
Do you mean that you want to have the "next pages" appear as

<<prev A B C D E F G next>>

instead of

<<prev 1 2 3 4 5 6 7 next>>

If that's what you want, I can't help you. I don't know.

Quote:
i don't really understand what you mean my 'static html page'

Some folks use an .html file to create predefined search links to DBMan for default users to use. I was just wondering if you were one of those folks.

I went to the page you suggested. I think you should know that it doesn't show anything for those using Netscape browsers. You're probably missing a closing </table> tag somewhere.

Here's what I can give you and you can see if it's what you want.

I can give you the code to print out the alphabetical links and do a search for companies that begin with each letter. I don't see how it can be part of the "List All" function, though.


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





Quote Reply
Re: Again - Alphabetical Listings In reply to
I can post it here. It's not that hard, really, and I've done it before. (The coding is a little ugly, 'cause I wrote it about a year ago and I've learned a lot since then. I'll try to clean it up as I go.)

On the page where you want to print out the links to do the searches, add

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>|;

This will print out the letters in a row, with brackets around them, each one having a link that will perform a search on the company field for records that start with the letter.

Be sure to watch out for the print qq| and |; syntax. It's hard to tell you exactly what to do, because I don't know what you already have in your script.


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







[This message has been edited by JPDeni (edited October 18, 1999).]

[This message has been edited by JPDeni (edited May 07, 2000).]
Quote Reply
Re: Again - Alphabetical Listings In reply to
I got it and its working fine.

There was one problem - I just cut and past the code into my script and when I ran it just floooded my browser -- realized you missed '$i++;'.

Thanks, this is what I wanted!

-Frank

Quote Reply
Re: Again - Alphabetical Listings In reply to
Sorry 'bout that. I'm glad you were able to find my mistake! Smile


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





Quote Reply
Re: Again - Alphabetical Listings In reply to
The example i gave you is not my site - just thought it would help explain what I was talking about.
cgi.jobs.com/cgi-bin/employer?zoneid=-1&letter=C - click on the link and then change the '..letter=C' in the address field to D and it should work.

Quote:
Do you mean that you want to have the "next pages" appear as
<<prev A B C D E F G next>>
This is exactly what I wanted.

Quote:
I can give you the code to print out the alphabetical links and do a search for companies that begin with each letter.

could you post the code? or email it to me - flthiak_asianart@wlink.com.np ?

Thanks JPD!
-frank


[This message has been edited by FLThiak (edited October 18, 1999).]
Quote Reply
Re: Again - Alphabetical Listings In reply to
So where does the $i++; go?
JR
Quote Reply
Re: Again - Alphabetical Listings In reply to
Sorry 'bout that. I'll put it in the code.


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






Quote Reply
Re: Again - Alphabetical Listings In reply to
THANK YOU, THANK YOU, THANK YOU JPD.

This is exactly what I was looking for in my other thread. No, it doesn't fix the prev/next part you and Lee were talking about in the long display, but this little code above, makes my life, and that of my alumni A LOT better.
Thx again.
JR
Quote Reply
Re: Again - Alphabetical Listings In reply to
You're welcome. Smile

I guess my memory isn't too good right now. What problem were you having with the prev/next part in the long display?


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






Quote Reply
Re: Again - Alphabetical Listings In reply to
Continued in http://www.gossamer-threads.com/...m12/HTML/002829.html , so as to not flood FLThiak's inbox. Thx.
JR