I am busy working on a university assignment which must do the following:
- Show list of sporting events for week
- User Submits the teams they think will win
- At end of week, calculate which users had the most correct picks
In working on above I have created a form like this, which lets the user select who they think will win.
The form data is collected from a database called events which looks like this:
My form is generate with the following code
//create form
echo'<form name="" action="" method="post">';
echo'<fieldset>';
echo'<legend>Make Your Picks</legend>';
//create query
$sql = "Select * FROM events";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
$team1 = $row['team1'];
$team2 = $row['team2'];
//dislay teams
echo'<h3>'.$team1.' VS '.$team2.'</h3>';
echo'<select name="'.$row['event_id'].'">';
echo'<option value="'.$row['team1'].'">'.$team1.'</option>';
echo'<option value="'.$row['team2'].'">'.$team2.'</option>';
echo'</select>';
}//while
echo'</legend></fieldset>';
echo'<input type="submit" class="buttono" value="Submit" name="submit" />';
echo'</form>'
I would like to get a more experienced users opinion on my logic and perhaps a tip if I am on the correct path and what I could be doing better, in terms of implementation,since I have ZERO confidence in my current approach.
- I am creating multiple selectboxes inside the while loop, each select box has a unique name of the event_id value from db which will get inserted into the picks database (see below), this doesn't seem very efficient is there an alternative way I can approach this?
Am I correct in assigning the name attribute of the selctbox the value of the fixture_id?
Is there perhaps a more efficient way I can approach this problem that you can suggest?
Just thought it would be interesting getting an experienced users view on this