|
.
|
<%args>
$results_page => 10
$search_type => 'album'
$sort_type => ''
$keywords => ''
$page => 1
%args>
<%init>
my $dbh = DBI->connect("DBI:mysql:allaboutjazz", 'vxweb', 'vx232web');
my ($id, $origfile, $album, $artist, $label, $author, $review, $pretty);
my ($s_page, $e_page);
$search_type = lc $search_type;
$search_type = 'album' if not $search_type =~ /^(album|artist|author|label)$/;
my $cnt_sql = "SELECT count(id) FROM cd_review WHERE MATCH($search_type) AGAINST(?)";
my $sth = $dbh->prepare($cnt_sql);
$sth->execute($keywords);
my ($total_cnt) = $sth->fetchrow_array();
$sth->finish();
my $sql = qq{ SELECT id, origfile, album, artist, label, author, review,
DATE_FORMAT(date_published, '%M %e, %Y') As PrettyDate
FROM cd_review
WHERE MATCH($search_type) AGAINST(?)
};
$sql .= " ORDER BY $sort_type " if $sort_type;
$sql .= " LIMIT ?,?";
my $sth2 = $dbh->prepare($sql);
my $offset = (($page-1) * $results_page) + 1;
$sth2->execute($keywords, ($page * $results_page) - $results_page, $results_page);
my $total_pages = int( $total_cnt / $results_page );
my $total_rpages = int ( $total_cnt % $results_page );
$total_pages++ if $total_rpages;
$e_page = ($page eq $total_pages and $total_rpages) ? (($page-1) * $results_page) + $total_rpages : $page * $results_page;
%init>
<%cleanup>
$dbh->disconnect();
%cleanup>
|
|
% if ($keywords) {
|
Sort By:
|
Displaying Results Per Page
|
% }
|
% if ($keywords and not $total_cnt) {
No Records Found!
% }
% elsif ($keywords) {
Search Results For: <% $keywords %>
Displaying Results <% $offset %> through <% $e_page %> of <% $total_cnt %>
<%perl>
while ( ($id, $origfile, $album, $artist, $label, $author, $review, $pretty) = $sth2->fetchrow_array() )
{
my $token;
foreach $token (split /\s/, $keywords)
{
$album =~ s#($token)#$1#ig if $search_type =~ /album/i;
$artist =~ s#($token)#$1#ig if $search_type =~ /artist/i;
$author =~ s#($token)#$1#ig if $search_type =~ /author/i;
$label =~ s#($token)#$1#ig if $search_type =~ /label/i;
}
%perl>
<% $album %>
Artist: <% $artist %>
Label: <% $label %>
Author: <% $author %>
Review Publish Date: <% $pretty %>
% }
% if ($total_pages > 1 ) {
Result Page:
% if ($page > 1) {
Previous
% }
% my $i=1;
% for ($i=1;$i <= $total_pages; $i++)
% {
<% ($i != $page) ? "$i" : "$i" %>
% }
% if ($page < $total_pages) {
Next
% }
% }
% }
|
|