Creating Rows and Columns Using for() Loops
| From: | php-list at xenonsolutions dot com | Date: | Thu, 08 Jul 2004 23:17:25 +0000 |
| Subject: | Creating Rows and Columns Using for() Loops | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-190009@lists.php.net to get a copy of this message | ||
Hello Everyone,
I have an HTML table with 7 columns and 32 rows, not including table headers
and footers. I want to create a tabular data table that spans 7 columns and
32 rows. I get my info from MySQL and use for() loops to loop through two
types of arrays. An array containing the dates (the columns) and a table
containing first and last names. The names will go underneath whichever date
it is associated with, with a maximum of 32 names per column (hence the 32
rows). I am using patTemplate to create the table. Here is what I have so
far:
for ($i = 0; $i < count($num_days); $i++) {
$template->addVar("date_column", "DAY",
$num_days[$i]['day_text']);
$template->addVar("date_column", "DATE",
$num_days[$i]['month_text'].'
'.$num_days[$i]['date']);
$template->parseTemplate("date_column", "a");
$template->addVar("sort_row", "SORT_FNAME", 'fname');
$template->addVar("sort_row", "SORT_LNAME", 'lname');
$template->addVar("sort_row", "SORT_RATE", 'rate');
$template->parseTemplate("sort_row", "a");
for ($j = 0; $j < 32; $j++) {
$template->addVar("guest_NameRate", "GUEST_NAME", 'BOB
RICHIE');
$template->addVar("guest_NameRate", "GUEST_ID", 'fname');
$template->addVar("guest_NameRate", "CLASS_GUEST",
'fname');
$template->addVar("guest_NameRate", "ROOM_RATE", '49.95');
}
$template->parseTemplate("guest_NameRate", "a");
$template->addVar("room_num", "ROOM_NUM", '101');
$template->addVar("room_type", "ROOM_TYPE", 'NQQ');
$template->parseTemplate("guest_row", "a");
}
I populated the guest's name statically so I can see how the loop works. The
looping is wrong and it only yields 7 rows. In the first row it has 1 column
of data, the second row has two columns of data, the third one has three
columns of data, and so on. How do I fix it to where each date column has
exactly 32 rows of guest names?
I hope this makes sense. Any help will be appreciated.