while loop to manage a team roster
Posted: Thu May 21, 2009 1:49 pm
I want to allow a coach to create and maintain a roster of 15 players (first name, last name, address, etc.).
To keep it simple, I want to use the same page/form to display an empty roster, as well as one that already has players.
The first time a coach loads the roster page, the form is empty; after entering 1 - 15 players, the form displays them.
The form should also display the existing fields so they can be edited, and should show 15 rows even if the coach has entered fewer players.
Updating values for any existing players, as well as entering values entered into any empty rows, would save upon submit.
Using while($row = mysql_fetch_array($result)) I can displays editable fields for however many players have been entered.
However, I need to get 15 rows and I need to have the field names in each row be different (in order for the INSERT/UPDATE query to work, right?).
I'm trying a while loop with a while loop like this...
This code gives me 15 rows, but the row values are not appearing, and the [$i] in the "player[$i]_roster_inches" is not iterating.
Am I at all on the right track?
Is there another way to do this?
Could really use some help!
To keep it simple, I want to use the same page/form to display an empty roster, as well as one that already has players.
The first time a coach loads the roster page, the form is empty; after entering 1 - 15 players, the form displays them.
The form should also display the existing fields so they can be edited, and should show 15 rows even if the coach has entered fewer players.
Updating values for any existing players, as well as entering values entered into any empty rows, would save upon submit.
Using while($row = mysql_fetch_array($result)) I can displays editable fields for however many players have been entered.
However, I need to get 15 rows and I need to have the field names in each row be different (in order for the INSERT/UPDATE query to work, right?).
I'm trying a while loop with a while loop like this...
Code: Select all
$result = mysql_query($sqlplayers);
$count=14;
$i=0;
while($i<=$count) {
while($row = mysql_fetch_array($result)); { ?>
<tr>
<td><?php echo tep_draw_input_field('player[$i]_roster_fname', $row['player_roster_fname'], 'size="10"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_lname', $row['player_roster_lname'], 'size="10"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_address', $row['player_roster_address'], 'size="15"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_city', $row['player_roster_city'], 'size="15"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_state', $row['player_roster_state'], 'size="2"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_zip', $row['player_roster_zip'], 'size="10"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_phone', $row['player_roster_phone'], 'size="10"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_email', $row['player_roster_email'], 'size="20"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_number', $row['player_roster_number'], 'size="2"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_gradyear', $row['player_roster_gradyear'], 'size="4"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_feet', $row['player_roster_height_feet'], 'size="1"'); ?></td>
<td><?php echo tep_draw_input_field('player[$i]_roster_inches', $row['player_roster_height_inches'], 'size="4"'); ?></td></tr>
<?php
}
$i++;
}Am I at all on the right track?
Is there another way to do this?
Could really use some help!