Looping comes in handy when you may want to execute a certain script “x” number of times or if you want to display all the information within a Recordset. Here is an example of how I display all the information stored within a Recordset into a nice table that is easy to read.
<!-- setting up the table -->
<table border=”1″>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Id</td>
</tr>
<?php //create the loop
do { ?>
<tr>
<td><?php echo $row_Recordset1['first_name']; ?></td>
<td><?php echo $row_Recordset1['last_name']; ?></td>
<td><?php echo $row_Recordset1['id']; ?></td>
</tr>
<?php //end the loop
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> |
This will display all the information for Recordset1 within a table with the heading cells being First Name, Last Name, and ID. Recordset1 must first be established before you will be able to populate the cells or else no data is found.