Link to parent pages

Jan Eden <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <r02010500-1039-15491E2FB01511D99C09000A959B4026@[10.149.23.127]>
Hi,

I employ a method to display lists of items ("children") for a "parent" page in my hierarchy described in the MySQL Cookbook by Paul DuBois (see the code below). Now is there a simple way to link back to the correct part of the splitted "parent" page from an item in the list?

I would like to avoid passing the start parameter around several times, as this information should follow from the position of the page within an ordered result of a SELECT query.

So can I use the LIMIT function to achieve the reverse?

Thanks,

Jan

sub index_links {
    my ($start, $link_mode, $item_id, $dbh) = @_;
    my %mode_hash = (
        page => { per_page => 30, table => 'pages', column => 'mother_id', href => '/', additional => ' AND VISIBLE = 1 AND site_id = 1'},
        author => { per_page => 30, table => 'pages, pages AS motherpages', column => 'pages.author_id', href => '/authors/', additional => ' AND pages.visible = 1 AND pages.site_id = 1 AND pages.mother_id = motherpages.page_id AND pages.author_id <> motherpages.author_id' },
        gallery => { per_page => 10, table => 'pictures', column => 'gallery_id', href => '/gallery/' },
    );
    my $index_type = $mode_hash{$link_mode};
    my ($rowcount) = $dbh->selectrow_array("SELECT COUNT(*) FROM $index_type->{table} WHERE $index_type->{column} = $item_id $index_type->{additional}");
    my $link_string = '';
    if ($rowcount > $index_type->{per_page}) {
        my @index_links;
        for (my $first = 1; $first <= $rowcount; $first += $index_type->{per_page}) {
            my $last = $first + $index_type->{per_page} - 1;
            $last = $rowcount if $last > $rowcount;
            my $label = "$first-$last";
            my $link;
            if ($first != $start) { $link = qq{<a href="$index_type->{href}$item_id?start=$first" target="_self">$label</a>}; }
            else { $link = $label; }
            push @index_links, $link;
        }
        $link_string .= qq{<p class="zentral">};
        $link_string .= join " | ", @index_links;
        $link_string .= qq{</p>};
    }
    return $link_string;
}
-- 
Life's unfair - but root password helps!

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.