Creating a Navigation Index from Database Content
Problem
A list of items in a web page is long. You want to make it easier for users to move around in the page.
Solution
Create a navigation index containing links to different sections of the list.
Discussion
It’s easy to display lists in web pages (Displaying Query Results as Lists). But if a list contains a lot of items, the page containing it may become quite long. In such cases, it’s often useful to break up the list into sections and provide a navigation index, in the form of hyperlinks that enable users to reach sections of the list quickly without scrolling the page manually. For example, if you retrieve rows from a table and display them grouped into sections, you can include an index that lets the user jump directly to any section. The same idea can be applied to multiple-page displays as well, by providing a navigation index in each page so that users can reach any other page easily.
This recipe provides two examples to illustrate these
techniques, both of which are based on the kjv
table that was introduced in Using FULLTEXT Searches. The examples
implement two kinds of display, using the verses from the book of
Esther stored in the kjv
table:
A single-page display that lists all verses in all chapters of Esther. The list is broken into 10 sections (one per chapter), with a navigation index that has links pointing to the beginning of each section.
A multiple-page display consisting of pages that each show the verses from a single ...
Get MySQL Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.