Database Reference
In-Depth Information
Displaying the Results
Now that the RecordSet name $RecordSet has been created and populated, we can process the
$RecordSet collection with the following code:
<!-- Page Headers -->
<H1>
The View Ridge Gallery ARTIST Table
</H1>
<hr />
<H2>
ARTIST
</H2>
<?php
// Table headers
echo "<table class='output' border='1'>
<tr>
<th>LastName</th>
<th>FirstName</th>
<th>Nationality</th>
</tr>";
// Table data
while($RecordSetRow = odbc_fetch_array($RecordSet))
{
echo "<tr>";
echo "<td>" . $RecordSetRow['LastName'] . "</td>";
echo "<td>" . $RecordSetRow['FirstName'] . "</td>";
echo "<td>" . $RecordSetRow['Nationality'] . "</td>";
echo "</tr>";
}
echo "</table>";
The HTML section defines the page headers, and the PHP section defines how to display
the SQL results in a table format. Note the use of the PHP command echo to allow PHP to use
HTML syntax within the PHP code section. Also note that a loop is executed to iterate through
the rows of the RecordSet using the PHP variable $RecordSetRow.
Disconnecting from the Database
Now that we have finished running the SQL statement and displaying the results, we can end
our ODBC connection to the database with the code:
// Close connection
odbc_close($Conn);
?>
The basic page we have created here illustrates the basic concepts of using ODBC and
PHP to connect to a database and process data from that database in a Web database process-
ing application. We can now build on this foundation by studying PHP command syntax and
incorporating additional PHP features into our Web pages. 7
Challenges for Web Database Processing
Web database application processing is complicated by an important characteristic of HTTP.
Specifically, HTTP is stateless; it has no provision for maintaining sessions between requests.
Using HTTP, a client at a browser makes a request of a Web server. The server services the
7 For more information on PHP, see the PHP documentation at www.php.net/docs.php .
 
Search WWH ::




Custom Search