Link to parent pages

Link to parent pages

am 18.04.2005 16:20:57 von Jan Eden

Hi,

I employ a method to display lists of items ("children") for a "parent" pag=
e in my hierarchy described in the MySQL Cookbook by Paul DuBois (see the c=
ode below). Now is there a simple way to link back to the correct part of t=
he 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 orde=
red 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) =3D @_;
my %mode_hash =3D (
page =3D> { per_page =3D> 30, table =3D> 'pages', column =3D> 'moth=
er_id', href =3D> '/', additional =3D> ' AND VISIBLE =3D 1 AND site_id =3D =
1'},
author =3D> { per_page =3D> 30, table =3D> 'pages, pages AS motherp=
ages', column =3D> 'pages.author_id', href =3D> '/authors/', additional =3D=
> ' AND pages.visible =3D 1 AND pages.site_id =3D 1 AND pages.mother_id =3D=
motherpages.page_id AND pages.author_id <> motherpages.author_id' },
gallery =3D> { per_page =3D> 10, table =3D> 'pictures', column =3D>=
'gallery_id', href =3D> '/gallery/' },
);
my $index_type =3D $mode_hash{$link_mode};
my ($rowcount) =3D $dbh->selectrow_array("SELECT COUNT(*) FROM $index_t=
ype->{table} WHERE $index_type->{column} =3D $item_id $index_type->{additio=
nal}");
my $link_string =3D '';
if ($rowcount > $index_type->{per_page}) {
my @index_links;
for (my $first =3D 1; $first <=3D $rowcount; $first +=3D $index_typ=
e->{per_page}) {
my $last =3D $first + $index_type->{per_page} - 1;
$last =3D $rowcount if $last > $rowcount;
my $label =3D "$first-$last";
my $link;
if ($first !=3D $start) { $link =3D qq{=
{href}$item_id?start=3D$first" target=3D"_self">$label
}; }
else { $link =3D $label; }
push @index_links, $link;
}
$link_string .=3D qq{

};
$link_string .=3D join " | ", @index_links;
$link_string .=3D qq{

};
}
return $link_string;
}
--=20
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/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org