Chapter 7 Lab
Generating Reports on Web Pages
The CGI script for this lab:
- Is called from an HTML page
- Connects to the Nile database and reads the rows from both the
title and transaction table.
- Generates a sales report, sorted by the number of titles sold, e.g.:
Book Sales Sorted by Quantity Sold
|2||Breathing for Dummies||33.99||56|
|1||The Idiot's Guide to Chewing||22.99||6|
|3||Walking Made Simple||199.99||1|
- Uses the following data structure:
Tasks to Do for this Lab
- Modify the CGI script so that it generates a column with total
revenue for each title, and sorts by total dollar amount (not the number sold),
Book Sales Sorted by Dollar Sales
|2||Breathing for Dummies||33.99||56||1903.44|
|3||Walking Made Simple||199.99||1||199.99|
|1||The Idiot's Guide to Chewing||22.99||6||137.94|
Extra for Experts
Instead of multiple CGI scripts for each kind of report,
it's better to just have one CGI script for all reports, and
have it run a particular subroutine depending on the user's choice.
One way to accomplish this is via the PATH_INFO variable.
This is text in the URL that occurs after the CGI script's name,
but before the question mark that would indicate the start of
the QUERY_STRING, e.g.
You can use the path_info method to get the value of the
We will use it to select which report subroutine we want called.
Tasks to Do for Extra for Experts
- Modify the HTML page to allow selection of a report sorted
either by revenue or by total sales and change the HREF to add
a keyword in the path info which your CGI script can check.
- Modify the CGI script to look in the PATH_INFO variable and
generate the proper report.
Dan Keller Technical Services © 2000