Hi,
I have built an index of a MySQL database using DBIx::FullTextSearch. I would like to provide previous/next and paged links. I have had a look at HTML::Pager and as I am also using HTML::Template this seems like the ideal solution.
I have poured over the documentation several times though I have to admit I'm no further forward. My first problem is DBIx::FullTextSearch only gives a resource id so I have to use this to query MySQL again and get some more interesting data such as resource title to show to the user. I can then put this into a hash and put this into a HTML::Template loop.
My first question then is.... which set of data do I apply HTML::Pager to the @files or @rows ? (see code below).
#!/usr/bin/perl
use CGI qw(param);
use DBIx::FullTextSearch;
use DBIx::FullTextSearch::StopList;
use DBI;
use HTML::Template;
my $dbh = DBI->connect('dbi:mysql:xxxx','xxxx','xxxxxx');
my $search = param("search");
my $fts = DBIx::FullTextSearch->open($dbh, 'fts_xxxx');
my @files = $fts->search($search);
if (@files)
{
foreach $filename(@files){
$filename = substr($filename,0,-4);
$sth = $dbh->prepare("SELECT id, title FROM resource WHERE id =
+?");
$sth->execute($filename);
while ($ref = $sth->fetchrow_hashref()){
$title = $ref->{title};
$id = $ref->{id};
push @rows, { ID => $id, TITLE => $title };
}
}
}
my $template = HTML::Template->new(filename => 'pg_search.tmpl');
$template->param(TAB_BG_MAIN => "#0B5875");
$template->param(TAB_BG_HEAD => "#6180BA");
$template->param(SEARCH => $search);
$template->param(ROWS => \@rows);
print "Content-type: text/html\n\n";
print $template->output;
I'm not 100% about the call back routine mentioned in the docs and how I'm going to pass this to HTML::Template but if anybody can point me in the right direction I would be most grateful.
Many thanks
./stew
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.