# this is a page script in the Tcl language, an interpreter for
# which is included within the AOLserver HTTP server. This is
# a free open-source program that has been used to serve billions of
# page requests from America Online's servers, e.g., www.aol.com.
# more info: http://en.wikipedia.org/wiki/AOLserver
# send basic text/html headers back to the client
# note that we just put characters in a Tcl string (by wrapping them in string quotes)
# and then call the AOLserver API function NS_WRITE to send them
# out to the browser
ns_write "HTTP/1.0 200 OK
MIME-Version: 1.0
Content-Type: text/html
"
# write the top of the page; we supply a static string of HTML
# as an argument to the NS_WRITE function and it will be sent
# to the browser.
ns_write "
Your Recent Transactions
Your Recent Transactions
"
# get an open database connection from AOLserver (which keeps a pool)
# and set the ID of that connection to the local variable DB
set db [ns_db gethandle]
# open a database cursor bound to the local variable SELECTION
# that will be the result of running a SQL query (the "SELECT *..." below)
# we want to read all the columns (*) from the transactions table
# but limit by account number and date (within the last 30 days)
# we'll ask for the rows back in descending order of transaction_date
# (i.e., the newest transactions first)
set selection [ns_db select $db "select *
from transactions
where account_number = 2727
and transaction_date > sysdate - 30
order by transaction_date desc"]
# loop through the cursor, calling NS_DB GETROW to bind
# the Tcl local variable SELECTION to a set of values for
# each row; it will return 0 when there are no more rows
# in the cursor
while { [ns_db getrow $db $selection] } {
# pull email and name out of SELECTION
set amount [ns_set get $selection amount]
set transaction_date [ns_set get $selection transaction_date]
set description [ns_set get $selection description]
# prepare an HTML "list item" for each transaction, wrapping
# the data items from the RDBMS in an - tag and also
# separating the items with colons.
ns_write "
- $transaction_date : $amount : $description
\n"
}
# close the unordered list that we opened with the UL tag above,
# then print out a page footer
ns_write "
Thank you for banking with us. Questions about your account? Call us at 800-555-1212.
"