Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Alphabetic list

(Page 1 of 2)
> >
Quote Reply
Alphabetic list
I'm working on a Links SQL database. It's working perfectly, but I've got a problem I hope somebody would help me with.

Is it possible to get Links to automaticly,
when building to make an alphabetic list of all links in the database?

If yes, how do you do this?

Martin Kjeldsen, for Webservice.dk
Quote Reply
Re: Alphabetic list In reply to
What do you mean? One very long list of all the links??
Quote Reply
Re: Alphabetic list In reply to
Hi Alex,

no it most browse the links not the categories. Can it work both ways that is browsing by categories and first letters.
Quote Reply
Re: Alphabetic list In reply to
I would like to have my site have a feature like on Snap:
http://www.snap.com/...tml?st.sn.fd.0.dir-4 .
Maybe you could do that by making a link to the search.cgi, but if there's another way I'd rather do that. Furthermore am I not sure how to search like that. The normal search in search.cgi says:

Ignored the following terms

a - Too Small

What I meant with the maincategories and the browsing by lettes separated is that I don't want a maincategory called a. I just want another way of browsing trough the links with one page for a, another for b etc.
Quote Reply
Re: Alphabetic list In reply to
I see what you mean... could you just create a category for each letter, then mod add.cgi to get the first letter of the thing and add it to that category as well? The database slow down I guess, but thats the only thing I can come up with.
Quote Reply
Re: Alphabetic list In reply to
First of all I've no idea of how you can do this and second of all would this the way I see create categories within my database. The best was if the database wasn't allowed to search in the alphabetic list and the main categories and the browsing by lettes separated.
Quote Reply
Re: Alphabetic list In reply to
It looks like they are doing what I thought I had suggested before....

Linking the status bar to a SEARCH rather than pre-genrated pages.

This would be a nice exercise for someone to do, a subroutine that would be able to be inserted into any of the build_page routines to add an alphabetic bar to a category, containing the sub-levels of that category.

The problem is that while Alpha is nice, there are too many variations -- so categorical and topical arrangements is still the best way to go -- even for browsing.

Quote Reply
Re: Alphabetic list In reply to
You would need to modify search.cgi to basically just do a search on category name only, and not use the search index. Something like:

SELECT ID, Name FROM Category WHERE Name LIKE 'a%'

to get all the categories that start with A.

Cheers,

Alex
Quote Reply
Re: Alphabetic list In reply to
Okay, then would can I do now. I can't wait for someone to make this. I've to do it very soon. Is there something easy to do. The speed is not the most important thing the most important thing is that it works like I want it to.
Quote Reply
Re: Alphabetic list In reply to
No, I would like to have all the links posted in a category a, b, c ,d etc, after the first letter in their title (sorted after all of the title of course).

Is it possible to do that. I don't want 24 categories with each letter in my maincategories. I want to have another way of browsing the database by letter instead of by categori.
Quote Reply
Re: Alphabetic list In reply to
I'm still not getting the idea.

You want to have the regular by-category listing, but you also want to be able to browse by alphabet? But you don't want that to show up?

Why not create a search page, that just lists the various options, then calls search.cgi to do it? Unless this is going to be the most popular way of browsing your site, it's probably not a bad way to go.

I've sort of asked this question before -- with pre-generated searches -- hopefully there will be a good solution in the near future.
Quote Reply
Re: Alphabetic list In reply to
Okay I hope it's me being to stupid, but Alex I still don't get it.

Can you tell step by step how to browse through the links where every link that start with the letter "a" is on one page. And also for the others.

How do you change search.cgi to only search on this and I still want to be able to search the "old" way.

Please help me to do this.
Quote Reply
Re: Alphabetic list In reply to
I'm still trying to work this out my self.

Can I search normally and still only search the first letter in Title (field). How do i do that. If a search on "a" i get this:

Ignored follwing terms:

- a too small

Help!
Quote Reply
Re: Alphabetic list In reply to
To do what you want, you'd need to code in a RLIKE expression (regular expression).

Code:
SELECT ID, Title FROM Links WHERE Title RLIKE '^[a|A]';

The docs say the search is case insensitive, but it doesn't work that way for me, the regex says to find any Titles that begin with a or A



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/







Quote Reply
Re: Alphabetic list In reply to
Oh, you can of course select any fields, such as:

Code:
SELECT * FROM Links WHERE Title RLIKE '^[a|A]';

Which would then make all the fields available and you could send it through the normal template processing --- link.html

I also posted a short description awhile back on how to add pages to Links. I used it for a bad-link report. It would work for a search such as this. TO make it generate the pages during a build, you'd need to add the routine to the nph-build process in the list of routines to go through.

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/







Quote Reply
Re: Alphabetic list In reply to
Thank you Pugdog it looks great, but still I don't know where I can make this change. You say I must make the code in regular expression, but where?

I'm sorry for all these stupid questions, but I've to ask you guys for help.

Thanks and hope you can help me again (again).
Quote Reply
Re: Alphabetic list In reply to
You must have posted the same time I did. I don't understand link.html is just the page regarding how links looks? I can not put any code (I think it's SQL code, right?) in there.

I don't know any Perl can I figure it out how to generate pages in nph-build.

Thanks again
Quote Reply
Re: Alphabetic list In reply to
How about this:

Code:
#!/usr/bin/perl

# Load required modules.
# ---------------------------------------------------
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links: BSQL;
use Links: B_Utils;
use Links::HTML_Templates;
use strict;
$|++;

&main();

sub main {
# ----------------------------------------------------
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
my $letter = $in->param('letter');
my $db = new Links: BSQL $LINKS{admin_root_path} . "/defs/Links.def";
my $query = qq!
SELECT * FROM Links
WHERE Title LIKE 'a%'
LIMIT 50
!;
my $sth = $db->prepare($query);
$sth->execute();
my $hits = $sth->rows();

my ($link, $output);
while ($link = $sth->fetchrow_hashref) {
$output .= &site_html_link ($link, $dynamic);
}
if ($hits) {
# Print out the HTML results.
&site_html_search_results ( { link_results => $output, category_results => '',
link_hits => $hits, cat_hits => 0, next => '', ignored => ''},
$dynamic );
}
else {
&site_html_search_failure ( { error => "No links found." }, $dynamic);
}
}

Save it as say letter.cgi, and then you can call:

letter.cgi?letter=a

and it will display all links that start with the letter a.

Pugdog, you don't need RLIKE, just use LIKE, it's faster.

Cheers,

Alex

[This message has been edited by Alex (edited December 23, 1999).]
Quote Reply
Re: Alphabetic list In reply to
Ok, two changes to the code:

Well, two changes and a reminder ---

Remember to change every smiley to a colon+D

1) you need to add:

Code:
my $dynamic = $in->param('d') ? $in : undef;
print $in->header();

The print header line, or you get a mal-formed header error and lot's of undefined parameters with -w

2) you need to change the select statement:

Code:

my $query = qq!
SELECT * FROM Links
WHERE Title LIKE '$letter%'
ORDER BY Hits Desc
LIMIT 50
!;

The IMPORTANT change is to replace the "a%" with "$letter%" ... the order by statement is just so you see where you can change how the order of the links are displayed. You can order by Title, Rating, whatever you want.


BTW... I have the code working at:

http://postcards.com/.../letter.cgi?letter=p

if you want to see what it does. You can create a page or a header bar you can <%include%> that has the searches coded in - or use a search with a select box, or anything.



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/









[This message has been edited by pugdog (edited December 23, 1999).]
Quote Reply
Re: Alphabetic list In reply to
Oops, thanks pugdog! You should also add in:

($letter =~ /^[a-z]$/) or ($letter = 'a');

Just so people can't mess up your SQL statement by putting in quotes, etc. At present you can only run one query at a time, but running multiple isn't too far off, so it's quite conceivable somebody could put:

'; DELETE FROM Links;

into letter and mess up your data.

Always be sure to quote the form input.

Cheers,

Alex
Quote Reply
Re: Alphabetic list In reply to
That's true!

I guess I should have really run it with -Tw since it's accepting input from the web.

It's a very important point to remember to make sure that ANY data your program is expecting is really "harmless"

It's really good form to screen out any "funny" characters such as >, <, ;, :, and others since Unix can do a lot of damage with stacked statements, pipes and pass throughs.

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/







Quote Reply
Re: Alphabetic list In reply to
Thank you both it really works great. I haven't tried the latest change but I've made it so that it's only predefined access to the file. Only a = letter.cgi?letter=a on so on, no < etc.

One tiny question. My database isn't made for English people and therefore I wouldn't like to have the error messages in English. Right now the database has only 2 links and therefore when using letter.cgi on a letter that doesn't exist, it returns Error: No links found. I know where to change error, but not where to change "No links found". I can't find the place where it's defined.
Quote Reply
Re: Alphabetic list In reply to
In the code I wrote you'll see:

&site_html_search_failure ( { error => "No links found." }, $dynamic);

Just change the message to whatever you like.

Btw Pugdog, I don't think taint mode would help there as I don't think it applies to passing input to DBI, but it is a good idea to use though!

Cheers,

Alex
Quote Reply
Re: Alphabetic list In reply to
Ok, (not being a real perl guru or hacker) is there a way to force taint (input) checking on web input -- before continuing on to the rest of the program?

Something idiot proof? If you remember to check it -- you don't need idiot proofing <G>


------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/







Quote Reply
Re: Alphabetic list In reply to
Pugdog,

No, -T is your best friend here. It will cause run time errors if you try and pass tainted information to any system functions, open calls, or a lot of other potentially hazardous stuff.

I don't think it will catch calls to DBI though.

Cheers,

Alex
> >