Displaying Query Results as Paragraph Text
Problem
You want to display a query result as free text.
Solution
Display it with no surrounding HTML structure other than paragraph tags.
Discussion
Paragraphs are useful for displaying free text with no particular
structure. In this case all you need to do is retrieve the text to be
displayed, encode it to convert special characters to the
corresponding HTML entities, and wrap each paragraph within
<p> and </p> tags.
The following examples show how to produce a paragraph for a status
display that includes the current date and time, the server version,
the client username, and the current database name (if any). These
values are available from the following query:
mysql> SELECT NOW( ), VERSION( ), USER( ), DATABASE( );
+---------------------+-----------------+----------------+------------+
| NOW( ) | VERSION( ) | USER( ) | DATABASE( ) |
+---------------------+-----------------+----------------+------------+
| 2002-05-18 11:33:12 | 4.0.2-alpha-log | paul@localhost | cookbook |
+---------------------+-----------------+----------------+------------+In
Perl, the CGI.pm module provides a
p( ) function that adds paragraph tags around
the string you pass to it. p( ) does not
HTML-encode its argument, so you should take care of that by calling
escapeHTML( ):
($now, $version, $user, $db) = $dbh->selectrow_array ("SELECT NOW( ), VERSION( ), USER( ), DATABASE( )"); $db = "NONE" unless defined ($db); $para = <<EOF; Local time on the MySQL server is $now. ...