Database Reference
In-Depth Information
CHAPTER 19
Generating Web Content from Query
Results
19.0. Introduction
Information stored in a database is easily retrieved for use on the Web in a variety of
ways. Query results can be displayed as unstructured paragraphs or as structured ele‐
ments such as lists or tables. Query metadata can be useful when formatting query
results, too, such as when generating an HTML table that displays a result set and uses
its metadata to get the column headings for the table. These tasks combine statement
processing with web scripting, and are primarily a matter of properly encoding special
characters in the results (such as & or < ) and adding the appropriate HTML tags for the
types of elements you want to produce.
This chapter shows how to generate several types of web output from query results:
paragraphs, lists, tables, hyperlinks, and navigation indexes (single- and multiple-page).
The chapter also covers techniques for inserting binary data into your database and for
retrieving and transferring that kind of information to clients. (It's easiest and most
common to work with text for creating web pages from database content, but you can
also use MySQL to service requests for binary data such as images, sounds, or PDF files.)
You can also serve query results for download rather than for display.
The recipes here build on the techniques shown in Chapter 18 for generating web pages
from scripts and encoding output for display. See that chapter if you need background
in these topics.
Scripts to create tables used in this chapter are located in the tables directory of the
recipes distribution. Scripts for the examples are located under the directories named
for the web servers used to run them. For Perl, Ruby, PHP, and Python examples, look
under the apache directory. Utility routines used by the example scripts are found in
files located in the lib directory. (For information on configuring Apache so that scripts
 
Search WWH ::




Custom Search