Database Reference
In-Depth Information
1. First item
2. Second item
3. Third item
You need not specify the item numbers because browsers add them automatically. An
ordered list is enclosed within <ol> and </ol> tags, and contains items each enclosed
within <li> and </li> tags:
<ol>
<li> First item </li>
<li> Second item </li>
<li> Third item </li>
</ol>
Suppose that an ingredient table contains numbered ingredients for a cooking recipe:
mysql> SELECT * FROM ingredient ORDER BY id;
+----+---------------------------------+
| id | item |
+----+---------------------------------+
| 1 | 3 cups flour |
| 2 | 1/2 cup raw ("unrefined") sugar |
| 3 | 3 eggs |
| 4 | pinch (< 1/16 teaspoon) salt |
+----+---------------------------------+
The table contains an id column, but you need only fetch the text values in the proper
order to display them as an ordered list because a browser adds item numbers itself.
The items contain the special characters " and < , so HTML-encode them before adding
the tags that convert the items to an HTML list. The result looks like this:
<ol>
<li> 3 cups flour </li>
<li> 1/2 cup raw ( &quot; unrefined &quot; ) sugar </li>
<li> 3 eggs </li>
<li> pinch ( &lt; 1/16 teaspoon) salt </li>
</ol>
One way to create such list from a script is by printing the HTML as you fetch the rows
of the result set. Here's how you might do so in a JSP page using the JSTL tag library:
<sql:query dataSource= "${conn}" var= "rs" >
SELECT item FROM ingredient ORDER BY id
</sql:query>
<ol>
<c:forEach items= "${rs.rows}" var= "row" >
<li><c:out value= "${row.item}" /></li>
</c:forEach>
</ol>
In PHP, perform the same operation like this:
$stmt = "SELECT item FROM ingredient ORDER BY id" ;
$sth = $dbh -> query ( $stmt );
Search WWH ::




Custom Search