in reply to Programmatically building named anchors to warp to sections
assuming your rows are sorted by name, you just need to get the relevant substring(), compare it to the 'current' substring, and print out an anchor when the new substring doesn't match the current one.
instead of printing, you'll probably want to append the content to a variable, and push each $section into a @list, so you can then print the navigation header before printing the output buffer.my $section = ''; while (my $row = $sth->fetchrow_hashref) { my $prefix = substr($row->{name}, 0, 2); if ($prefix ne $section) { $section = $prefix; print qq{<a href="#$section">$section</a>}; } # do the usual }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Programmatically building named anchors to warp to sections
by ww (Archbishop) on Aug 15, 2007 at 12:19 UTC | |
Re^2: Programmatically building named anchors to warp to sections
by mr_mischief (Monsignor) on Aug 15, 2007 at 02:07 UTC | |
by mreece (Friar) on Aug 15, 2007 at 03:57 UTC | |
by mr_mischief (Monsignor) on Aug 15, 2007 at 15:10 UTC | |
by mreece (Friar) on Aug 15, 2007 at 16:34 UTC | |
by mr_mischief (Monsignor) on Aug 15, 2007 at 19:05 UTC | |
|
In Section
Seekers of Perl Wisdom