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 |
| ID | Title | Price | Qty |
| 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),
e.g.:
Book Sales Sorted by Dollar Sales |
| ID | Title | Price | Qty | 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 |
|
Solution
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.
http://path/to/the.cgi/this/is/path_info?query_string
You can use the path_info method to get the value of the
PATH_INFO variable.
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.
Solution