Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Link to record starting with...

Quote Reply
Link to record starting with...
I want to make a link to list all records starting with a letter. This could be done with version 1 like this:

^a (or somthing like this)

But how can I do this with V2?

The following link will get all records with the letter A in this filed. I want all starting with A.

<a href="http://www.mysite.com/db/db.cgi?db=name&do=search_results&details=1&name=A&id=1">Letter A</a>




Quote Reply
Re: [kjetilpalm] Link to record starting with... In reply to
Hi,

Follow the following steps:

1. In template global, add the sub-routine:

sub letter_search{
#-----------------------------------------------
#
my $tags = shift;
my $letter = $tags->{letter};
my $sql = $tags->{home}->{sql};
my $db = $tags->{db};
my $table = $sql->table($db);
my $sth = $table->select ( GT::SQL::Condition->new ('Column', 'LIKE', "$letter%"));
my @output;
while (my $hash = $sth->fetchrow_hashref ) {
push @output, $hash;
}
return { letter_loop => \@output };
}

2. in search_results.html, add some scripts:
.....
<%if letter%>
<%letter_search%>
<%loop letter_loop%>
<p><%Dbsql::HTML::generate_search_results%>
<%endloop%>
<%else%>
<%loop results%>
................
<%endloop%>
<%endif%>

3. create a link:
<a href=db.cgi?db=<%db%>&do=search_results......&letter=A>A</a>

Cheers,
TheStone


B.

Last edited by:

TheStone: Oct 17, 2001, 2:15 PM
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Hello,

A very, very basic question (I am just starting): how do you edit Template Globals? I copied and pasted the scripts in DBMan SQL Admin --> Templates -->Template Globals, in the Description area. I then followed the second and third step. What I got was:

You must specify at least one search term

Thanks

Jian
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

The link should be:
<a href=db.cgi?db=<%db%>&do=search_results&keyword=*&letter=A>A</a>

Cheers,
TheStone.

B.
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Thanks. But now I am getting:

Unknown Tag: 'letter_search'

I guess I am still not sure if the first step was correct.


Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Let me ask this question again, in a different way: which file should I edit directly to add the codes? It seems to me that when I copied and pasted the codes as I did, nothing happened. I thought I could add the codes directly to the file, but I am not sure which file.

Thanks again.


Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

Alright, first of all you have to create letter_search subroutine in template global (goto Admin - Template - Template Globals)

After that, modify search_results.html (in default template folder), add some scripts ( take a look at step 2 in my posted)

And then add a link <a href=db.cgi?db=<%db%>&do=search_results&keyword=*&letter=A>A</a> in footer.html, header.html or home.html

Cheers,
TheStone.


B.

Last edited by:

TheStone: Dec 31, 2001, 11:01 AM
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Hello

Sorry to bother you again. But I still can't make this work. I followed your instructions very closely. And I think I have some progress. The search seemed to be excuted, and I got the correct number of hits back, followed with the codes for letter_search, but no list.

I ended up adding a new column for alphabetical browsing, which is very clumsy and time consuming to maintain. See http://www.indiana.edu/~libej/new.html .

Any more suggestions?

Thanks
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

Can you send me the username and password to connect to your Admin panel?, I'll take a look at it by fileman

Cheers,

TheStone.

B.

Last edited by:

TheStone: Jul 16, 2003, 1:07 PM
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi Jian,

I think that in this case you should create a plugin to do it, that should be better than using Global template. Let take a look at the attached file which is the LetterSearch plugin.
First of all you have to install this plugin, and then create a link like: <a db.cgi?do=search_results&db=<%db%>&let=a_letter&col=column_name">A</a>. That should list all records staring with A letter.

Hope that helps,

TheStone.

B.

Last edited by:

TheStone: Jan 11, 2002, 12:18 PM
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Oh thanks. This is really cool. Thanks a lot. Works wonderfully.

Two more related questions:

1. The plugin doesn't seem to care the number of hits returned. It just retrieves all the records for a specific letter. I tried to add &mh=25 to the line, to no effect. See: http://www.indiana.edu/~librcsd/test/db.html

2. I realize, to my happy surprise, that I can use this plugin to provide a better browsing function, for example, I can enter "journal of" as the letter and it will retrieve records beginning with "journal of", which is better than simply J. I guess I can create a input form, and have users supply whatever words they want to begin to browse. Right? And if so, how? :-)

Thanks again
Jian Liu
Indiana University Libraries

Last edited by:

jiliu: Jan 11, 2002, 12:56 PM
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

Quote:
1. The plugin doesn't seem to care the number


Oops.. I forgot, let uninstall the plugin and change LetterSearch.pm:
GT::Plugins->action ( STOP );
my $rows = $home->{cgi}->{mh} || 25;
my $pg_current = $home->{cgi}->{nh} || 1;
my $rec_start = ($pg_current == 1) ? 0 : ($pg_current-1)*$rows;
my $limit = "LIMIT ".$rec_start.",".$rows;

my $db = $home->{cgi}->{db};
my $table = $DB->table($db);
$table->select_options($limit);
my $sth = $table->select ( GT::SQL::Condition->new ($column, 'LIKE', "$letter%") );
my $hits = $table->hits();
....

Quote:
2. I realize, to my happy surprise,


Definitely, just create a search form like:
<input type=hidden name="db" value="<%db%>">
<input type=hidden name="do" value="search_results">
<input type=hidden name="col" value="field_name">
<input type=text name="let" value="">
That should work as what you're supposed to be.

Cheers,

TheStone.

B.

Last edited by:

TheStone: Jan 11, 2002, 1:52 PM
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Thanks a lot. This is working nicely.

Some tweeking may still be needed, for the sorting of results seems strange. For example, browsing for the letter Z gives all titles beginning with Z, but Zacks Investment comes after Zoological Science, etc. Could this be fixed?

Thanks again
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

Replace: $table->select_options($limit);
With: $table->select_options("Order by $column",$limit);

Cheers,
TheStone.

B.
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
THANK YOU!

This is working perfectly.
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hello

I am back with an urgent request for help, still related to this thread. Hopefully you would be able to help like you did excellently several months ago.

I am developing another database using the plugin. Please take a look at:

http://www.indiana.edu/...d/dbman/db.cgi?db=NT

I need to be able to browse by call number, and the plugin works. But I also need to be able to limit the results by libraries or by Main Library shelf location (the first two options). But this doesn't seem to work. If I choose, say, Main Library - Research Coll. - Stacks from Select a Main Library Shelf Location:, and enter HM in the Browse by Call Number: section, I will get records with call numbers beginning with HM, but they are from all libraries, not just the one I chose.

Anyway to fix this? Your help is greatly appreciated.

Thanks
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi Jian,

You should modify your script like:
Code:
...
else {
$cond->add($column,'LIKE',"$letter%");
}
my $cols = $table->cols;
my $c = GT::SQL::Condition->new();
foreach ( keys % $cols ) {
if ( $home->{cgi}->{$_} ) {
my $opt = $home->{cgi}->{"$_-opt"} || 'LIKE';
( $opt eq 'LIKE' ) ? $c->add($_, $opt, "$home->{cgi}->{$_}%") : $c->add($_, $opt, $home->{cgi}->{$_});
}
}

my $sth = $table->select (GT::SQL::Condition->new($c, $cond));


Hope that helps.

TheStone.

B.

Last edited by:

TheStone: Apr 19, 2002, 2:09 PM
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Thanks. I tried it but I got:

A fatal error has occured:
GT::Plugins (10867): Error running plugin PRE hook: Plugins::Dbsql::LetterSearch::letter_search. Reason: Global symbol "$hits" requires explicit package name at /ip/librcsd/www/dbman/admin/Plugins/Dbsql/LetterSearch.pm line 95.Global symbol "$hits" requires explicit package name at /ip/librcsd/www/dbman/admin/Plugins/Dbsql/LetterSearch.pm line 101.Global symbol "$hits" requires explicit package name at /ip/librcsd/www/dbman/admin/Plugins/Dbsql/LetterSearch.pm line 103.Global symbol "$hits" requires explicit package name at /ip/librcsd/www/dbman/admin/Plugins/Dbsql/LetterSearch.pm line 115.Compilation failed in require at /ip/librcsd/www/dbman/admin/GT/Plugins.pm line 247. at /ip/librcsd/www/dbman/admin/Dbsql/Home.pm line 75.


Please enable debugging in setup for more details

I wish I knew how to fix it, instead of bothering you again. :-(


Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] Link to record starting with... In reply to
Hi,

I guess that you missed the command below:
my $hits = $table->hits;

TheStone.

B.
Post deleted by jiliu In reply to
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Hello,

I just realized that the change of the Plugin script renders my main service at http://www.indiana.edu/~libej . I had to put the old, working version back. How should I make it work whlie the regular service will not be affected?

thanks
Jian Liu
Indiana University Libraries
Quote Reply
Re: [TheStone] Link to record starting with... In reply to
Have followed this thread and installed the plug in. Results are sames as Jiliu's first go. I get the hit number, but not the results.

1) Install plug in.
2) Add Path To Header
<a href="/cgi-bin/membersSQL/db.cgi?do=search_results&db=<%db%>&let=A&col=LastName">A</a>
3) Tried several mods to search_results.html - example:

<%else%>
<%loop results%>
<p><%Dbsql::Relation::HTML::generate_search_results%>
<%endloop%>
<%endif%>
<%else%>

<%if letter%>
<%letter_search%>
<%loop letter_loop%>
<p><%Dbsql::HTML::generate_search_results%>
<%endloop%>
<%else%>

<%loop results%>
<p><%Dbsql::HTML::generate_search_results%>
<%endloop%>
<%endif%>
Quote Reply
Re: [gatman] Link to record starting with... In reply to
hi,

have a look here:

http://www.gossamer-threads.com/...i?post=232206#232206

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.
Quote Reply
Re: [ManuGermany] Link to record starting with... In reply to
Many Thanks

I never saw that thread. It worked

Regards

John