Reputation: 723
I have a couple of tables that show data from the same table but instead of all in one table, they are split according to their column name. I also have radio buttons for the user to check which team they want to support.
What i need to do is, according to the users choice, i wanna pass that information onto the database as an integer. So if the user picks 'home' and point difference is '12', it should pass as 12 to a table, of the user picks 'away' and point difference as '12', it should pass as -12 in the table.
I kinda understand how to do this in php but i have a total of 9 tables for the games, i dont want to be sitting here creating 18 if statements, i was wondering if there is an easier way to do it.
<tr><b><h4>Game 1</h4></b>
<th>Home</th><th>Away</th>
</tr>
<?php
while ($row = mysql_fetch_array($rs)){?>
<tr>
<td><input type="radio" id="home1" name="game1" onchange="tip();" value="<?php'.$row['home1'].'?>" > <?php echo $row['home1']?></td>
<td><?php echo $row['away1']?><input type="radio" id="away1" name="game1" value="<?php'.$row['away1'].'?>"></td>
</tr>
<?php }?>
</table>
Point Difference: <input type="text" id="g1diff" name="g1diff" size=5 />
<table border="1">
<tr><b><h4>Game 2</h4></b>
<th>Home</th><th>Away</th>
</tr>
<?php
mysql_data_seek($rs, 0);
while ($row = mysql_fetch_array($rs)){?>
<tr>
<td><input type="radio" id="home2" name="game2"value="<?php'.$row['home2'].'?>"><?php echo $row['home2']?></td>
<td><?php echo $row['away2']?><input type="radio" name="game2" value="<?php'.$row['away2'].'?>"></td>
</tr>
Point Difference: <input type="text" id="g2diff" name="g2diff" size=5 />
<?php }?>
</table>
Since the only difference between, home1 and home2 is the last digit, is there anyway to do it dynamically for all 'home' selects and all 'away' selects.
Upvotes: 0
Views: 54
Reputation: 21533
It rather sounds like your database design is not normalised (multiple columns like).
However if I understand your requirements then you want to put out 9 HTML tables of details for each row. Probably easiest to set up an array to store the 9 tables, then loop around the rows, and for each row take the relevant columns and update the array of tables to be output. Once all the data is processed you can then output them.
Something like this:-
<?php
$games = array();
for($aCnt = 1; $aCnt <= 9; $aCnt++)
{
$games[$aCnt] = "<table border='1'><tr><b><h4>Game ".$aCnt."</h4></b><th>Home</th><th>Away</th></tr>";
}
while ($row = mysql_fetch_array($rs))
{
for($aCnt = 1; $aCnt <= 9; $aCnt++)
{
$games[$aCnt] .= " <tr>
<td><input type='radio' id='home".$aCnt."' name='game".$aCnt."' onchange='tip();' value='".$row['home'.$aCnt]."' > ".$row['home'.$aCnt]."</td>
<td>".$row['away'.$aCnt]."<input type='radio' id='away".$aCnt."' name='game".$aCnt."' value='".$row['away'.$aCnt]."'></td>
</tr>";
}
}
for($aCnt = 1; $aCnt <= 9; $aCnt++)
{
$games[$aCnt] .= "</table> Point Difference: <input type='text' id='g1diff' name='g".$aCnt."diff' size=5 />";
echo $games[$aCnt];
}
?>
Upvotes: 1