Hi,
I'm trying to group dynamic form values to Insert into a database using php and mysql.
The background is that I'm trying to develop a web based Football Prediction League.
I'm retrieving the following values from my Fixtures table
Fixid, Team1Name, Team2Name
and populating a HTML form where the user will enter, obviously enough, the goals for either team
My HTML form displays
Team1 Name Team 1Goals Team2 Goals Team2 Name
I want to submit this form to another page which will insert the following values into a Prediction table
Prediction Id, UserId,FixtureId,Team1 Goals, Team 2 Goals
The code is
HTML Code:<form name="fixtures" action="target.php" method="get"> <table class="fixtures"> <tr> <th>Team 1</th><th>Goals</th><th>Goals</th><th>Team 2</th> </tr>PHP Code:<?php
while ($row = $res->fetch_array(MYSQLI_NUM)) {
echo '<input type="hidden" name="fixture[]" value ="'.$row[0].'">';
echo '<td>'.$row[2].'</td><td><input type="text" name="f'.$row[0].'t1g" id="f'.$row[0].'t1g" value="" maxlength="3" class="fixtures" /></td>';
echo '<td class="fixtures"><input type="text" name="f'.$row[0].'t2g" id="f'.$row[0].'t2g" value="" maxlength="3" /></td>';
echo '<td>'.$row[4].'</td>';
echo '</tr>';
}
?>My difficulty is how do I deal with the values coming in when the page is submitted. I've tried doing a foreach loop on the $_GET array for all values but cant seem to figure out how I a group each teams goal prediction with the relevant fixture idHTML Code:</table> <input class="wsubmit" type="submit" name="submit" value="Submit" id="submit" /> <input class="wreset" type="reset" name="reset" value="Reset" id="reset" / </form>
i.e. something like insert into prediction userid,fixid,team1goals, team2goals where fixid = 1 and loop this for, say, 10 fixtures....
What would be the best approach for grouping the variables so I can achieve this ?
Should I change my original form ? Can I incorporate the fixtures array in the hidden field ? Can I group or make an array from the values in the $_GET array ? so many questions!
Many thanks in advance for any help,
alan




Bookmarks