304
Display the Contents of a Table on a Web Page ..........
4 Type $query = “SELECT
field1, field2 FROM
table”;, replacing field1
and field2 with the names of
the fields from your database
and table with the table
name. Add additional fields,
separated by commas, if
necessary.
1 In your editor, open a new
PHP page.
2 At the top of the code, type
<?php.
3 Type include(“?”);,
replacing? with the path to
the file that contains the
connection code.
Note: See the previous section
for details on creating this file.
Display the Contents of a Table on a Web Page
Y
ou can use PHP and a SQL statement to return the records from a table and display them on a
Web page. In PHP, you can create a variable that stores the SQL statement. SQL can return the
records in a table with its SELECT statement. Following the SELECT keyword, you put the names
of the fields you want to return, followed by the FROM keyword and the name of the table. Once
you have created the SQL statement, you can call the PHP mysql_query() function, passing the
variable with the query as the function’s argument.