Hi All,
PHP newbie here.
Getting to grips with various aspects of learning PHP however i seem to have hit a bit of a stumbling block.
The below code loops through my $available_games (foreach from what i have read is the best way to do this) and outputs a nice table. Users then click on the Sign Up button where they input some details in a form to signup.
I am displaying the value from the hidden input box (name="game_name") on the next page so i know what game they have signed up for and can insert this into the database.
However currently this only displays the final $available_games['game_name'] in the list (ie if there are 2 available it always shows the 2nd, even if they select the 1st available game - there could be more than 2 but in my test example i am using 2)
I want the <input type="hidden" name="game_name" value="<?php echo $available_games['game_name']?>"/> value to be the correct one depending on where in the loop of $available_games it is at. (Ie 1st available game then keep this value and display on the next page - if 2nd is chosen then use this etc etc)
I have looked at producing a variable variable in a loop but couldn't get this to work. Any help is appreciated.
foreach($available_games as $available_games) {
echo "<tr>";
echo "<td>";
$game_name = $available_games['game_name'];
$_SESSION['game_name'] = $game_name;
echo "<center>" . $game_name . "</center>";
echo "</td>";
echo "<td>";
echo "<center>" . $available_games['speed_modifier'] . "</center>";
echo "</td>";
echo "<td>";
$open = strtotime($available_games['open_date']);
$open_date = date("d-m-Y H:i", $open);
echo "<center>" . $open_date . "</center>";
echo "</td>";
echo "<td>";
$close = strtotime($available_games['close_date']);
$close_date = date("d-m-Y H:i", $close);
echo "<center>" . $close_date . "</center>";
echo "</td>";
echo "<td>";
?>
<input type="hidden" name="game_name" value="<?php echo $available_games['game_name']?>"/>
<form action="signup.php" method="POST">
<input type="submit" name="signup" value="Sign Up"/>
<?php
echo "</td>";
echo "</tr>";
}
echo "</table>";