Database Reference
In-Depth Information
Creating a single-page navigation index
This example displays all verses in Esther in a single page, with verses grouped into
sections by chapter. To display the page so that each section contains a navigation
marker, place an
<a name>
anchor element before each chapter's verses:
<a
name=
"1"
>
Chapter 1
</a>
...
list of verses in chapter 1
...
<a
name=
"2"
>
Chapter 2
</a>
...
list of verses in chapter 2
...
<a
name=
"3"
>
Chapter 3
</a>
...
list of verses in chapter 3
...
…
That generates a list that includes a set of markers named
1
,
2
,
3
, and so forth. To
construct the navigation index, build a set of hyperlinks, each of which points to one of
the
name
markers:
<a
href=
"#1"
>
Chapter 1
</a>
<a
href=
"#2"
>
Chapter 2
</a>
<a
href=
"#3"
>
Chapter 3
</a>
…
The
#
in each
href
attribute signifies that the link points to a location within the same
page. For example,
href="#3"
points to the anchor with the
name="3"
attribute.
To implement this kind of navigation index, use one of these approaches:
• Retrieve the verse rows into memory and determine from them the entries needed
in the navigation index. Then print both the index and verse list.
•
Figure out all the applicable anchors in advance and construct the index first. This
statement determines the list of chapter numbers:
SELECT
DISTINCT
cnum
FROM
kjv
WHERE
bname
=
'Esther'
ORDER
BY
cnum
;
Use the query result to build the navigation index, then fetch the verses for the
chapters later to create the page sections to which the index entries point.
Here's a script,
esther1.pl
, that uses the first approach. It's an adaptation of one of the
nested-list examples shown in
Recipe 19.2
:
#!/usr/bin/perl
# esther1.pl: display the topic of Esther in a single page,
# with navigation index
use
strict
;
use
warnings
;
use
CGI
qw(:standard escape escapeHTML)
;
use
Cookbook
;
my
$title
=
"The Topic of Esther"
;