sws Posted November 30, 2006 Share Posted November 30, 2006 I have a mysql table that contains the entire nhl schedule in it. Fields in the table are as follows:IDHome TeamVisiting TeamDateI'm trying to create a form that lists every game being played on that particular date (always today) with radio buttons beside each team name.Basically what I'm trying to accomplish is to display a form that shows every game for that day and to let the user pick a winner for each game. How to I populate the form with JUST the games for the present day ?Also, How do I write the picks to the database. Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 30, 2006 Share Posted November 30, 2006 First make sure the field isn't called "date" this confuses PHP. change it to "game_date" or something. I'll use that in this little walkthroughpopulate it:[code]<?php// How you pull the date depends on how you store the date.// Look into the "date" function for better understanding$query = mysql_query("SELECT * FROM table WHERE game_date='".NOW()."'") or die(mysql_error());?><form name="nhl" action="" method="POST">Home : Away<?phpwhile($row = mysql_fetch_array($query)){ echo "<input type='radio' name='bet[".$row['id']."]' value='home_team'> : <input type='radio' name='bet[".$row['id']."]' value='visiting_team'> - ".$row['home_team']." VS. ".$row['visiting_team']."<br>";}?></form>[/code]and then fix the code to place the bets (assuming thats what your doing here).Fields in this case are "id, home_team, visiting_team, game_date" Quote Link to comment Share on other sites More sharing options...
sws Posted November 30, 2006 Author Share Posted November 30, 2006 Thanks Jocka.I'll implement this. Once I have this working, how would I then enter the picks into the database ? I'll need to createa table containing the user's id and all of the pick values each day.Any advice on how I should set that up ? Quote Link to comment Share on other sites More sharing options...
craygo Posted November 30, 2006 Share Posted November 30, 2006 This will work as long as the Date field is actually a date field and not a char field[code]<?phpif(!isset($_POST['submit'])){echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=POST>";echo "<table width=800 align=center><tr><td width=200>Home Team</td><td width=200>Away Team</td><td width=100>Select</td></tr>";$today = date("Y-m-d");$sql = "SELECT * FROM nhltable WHERE Date = $date ORDER BY Date ASC"; $res = mysql_query($sql) or die (mysql_error()); while($r = mysql_fetch_assoc($res)){ echo "<tr> <td>".$r['Home Team']."</td> <td>".$r['Away Team']."</td> <td><input type=radio name=gameid value=".$r['ID']."></td> </tr>";}echo "<tr> <td colspan=3 align=center><input type=submit name=submit value=Submit></td> </tr> </table>";} else {// put your code for after the submit}?>[/code]Ray Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 30, 2006 Share Posted November 30, 2006 just a table called "game_bets" with fields like "bet_date, user_id, game_id, user_bet" -- date, user id, the "game" id and their bet of course.I forgot a submit button by the way so throw that in the form before "</form>"[code]<?php// first we find our resultsif(isset($_POST['bet'])){ // check to see if bet was sent to the page // DO YOUR CHECK TO SEE IF THEY ARE LOGGED IN // WE'LL CALL $user_id FOR THE ID YOU HAVE FOR THE LOGGED IN USER foreach($_POST['bet'] as $id => $bet){ // id is game id and bet is their choice $query = mysql_query("INSERT INTO `game_bets` VALUES (NOW(), '".$user_id."','".$id."','".$bet."')") or die(mysql_error()); // dies on error}// ALL IN DATABASE?>[/code] Quote Link to comment Share on other sites More sharing options...
sws Posted November 30, 2006 Author Share Posted November 30, 2006 Thanks guys !I really appreciate the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.