Database Reference
In-Depth Information
% ( urllib . quote ( website ), cgi . escape ( name , 1 )))
cursor . close ()
# print items, but don't encode them; they're already encoded
print ( make_unordered_list ( items , False ))
CGI.pm-based Perl scripts produce hyperlinks with the a() function:
a ({-href => " url-value "}, " link label ")
Use the function to produce the vendor link list like this:
my $stmt = "SELECT name, website FROM book_vendor ORDER BY name" ;
my $sth = $dbh -> prepare ( $stmt );
$sth -> execute ();
my @items ;
while ( my ( $name , $website ) = $sth -> fetchrow_array ())
{
push ( @items , a ({ - href => "http://$website" }, escapeHTML ( $name )));
}
print ul ( li ( \ @items ));
Ruby scripts use the cgi module a method to produce hyperlinks:
stmt = "SELECT name, website FROM book_vendor ORDER BY name"
list = ""
dbh . execute ( stmt ) do | sth |
sth . fetch do | row |
list << cgi . li {
cgi . a ( "href" => "http:// #{ row [ 1 ] } " ) {
CGI . escapeHTML ( row [ 0 ]. to_s )
}
}
end
end
list = cgi . ul { list }
Generating links using email addresses is another common web programming task.
Assume that a table named newsstaff lists the department, name, and (if known) email
address for the news anchors and reporters employed by a television station, WRRR:
mysql> SELECT * FROM newsstaff;
+------------------+----------------+-------------------------+
| department | name | email |
+------------------+----------------+-------------------------+
| Sports | Becky Winthrop | bwinthrop@wrrr-news.com |
| Weather | Bill Hagburg | bhagburg@wrrr-news.com |
| Local News | Frieda Stevens | NULL |
| Local Government | Rex Conex | rconex@wrrr-news.com |
| Current Events | Xavier Ng | xng@wrrr-news.com |
+------------------+----------------+-------------------------+
From this you want to produce an online directory containing email links to all per‐
sonnel, so that site visitors can send mail to any staff member. For example, a row for
Search WWH ::




Custom Search