Blog

Newest Post
Blog Archives
Blog Categories

Portfolio

3D Models
Banners
Brochures
Business Cards
Custom Programming
Environments
Flash Projects
Game Design
Image Altering
Web Design

About

Resume
Recommendation Letters

Contact

November 21, 2007

Looping with PHP to Build a Table

Filed under: PHP — admin @ 12:00 pm

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.

Leave a Reply

© - Digital Epiphany Designs, Online Portfolio for Web Design, Custom Programming, Grapic Design and Game Design.