Tutorial
|
|||
|
Interfacing with the database.
In the previous tutorials you saw how the TT Web Site Manager could be used to create pages with a mixture of static HTML and PHP code all dynamicaly served on the fly. This tutorial demonstrates how TT Web Site Manager pages can be interfaced with database tables as well as covering the use of conditional items and user input in the TT Web Site Manager. Before we can do any work with a database we must create a table to hold our data. For the purposes of this tutorial we are creating a single table with three columns to store a very simple list of text strings. The SQL to create this table on a MySQL database server is shown below.
CREATE TABLE `data` ( The easiest way to create the table is to run the above SQL in the TT Web Site Manager's SQL prompt.
We have already covered creating pages in an earlier tutorial so you will be able to create a new page for this tutorial (in our example called dbpage) without further instructions.
You will now create an HTML table into which you will list the contents of the database table. First create simple static HTML items for the top and bottom of the table.
To list the contents of the database table in an HTML page you will have to use a PHP with SQL wrapper item. This is a piece of PHP code or static HTML which is run once for every line returned in the recordset from an acompanying SQL query, with the data from that line being made available to it. In this case the item runs a simple select from the data table and constructs a table row with the returned data for each record.
Having created the items, assemble them into your page in the order shown, along with the HTML header and footer items.
Displaying the page will now list the contents of the data table in an HTML table. Of course, as the table now stands it has no data in it so in fact the page will give you an empty table as ahown below. The next step will be to add a form to enter new data, and some SQL code to put that data in the database.
|
|||
|