306
Display the Contents of a Table on
a Web Page (continued)
! Type echo $row[‘?’].
“ “;, replacing? with the
name of the first field you
want to display.
@ Repeat Step 11 for each
additional field.
Type echo ‘””’;.
7 Within the body of the page,
type <?php.
8 Type while($row =
mysql_fetch_
array($data,
MYSQL_ASSOC)).
9 Type {.
0 Type echo “<p>”;.
Display the Contents of a Table on a Web Page (continued)
O
nce you have created the SQL statement and executed the query, you can display the results by
using a PHP where loop. A loop executes a set of code repeatedly; in this case, you want the
code that displays the data to repeat for each record. The data is converted into an array, a special
type of data that holds multiple values, by calling the mysql_fetch_array function, and
passing to it the variable you used when you called the mysql_query function. You can reference
the values by giving the name of the array and, in square brackets, the name of the field.