Jump to content

newbie questions


sws

Recommended Posts

I have a mysql table that contains the entire nhl schedule in it. Fields in the table are as follows:

ID
Home Team
Visiting Team
Date

I'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.
Link to comment
https://forums.phpfreaks.com/topic/28974-newbie-questions/
Share on other sites

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 walkthrough
populate 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
<?php
while($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"
Link to comment
https://forums.phpfreaks.com/topic/28974-newbie-questions/#findComment-132716
Share on other sites

This will work as long as the Date field is actually a date field and not a char field
[code]<?php
if(!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
Link to comment
https://forums.phpfreaks.com/topic/28974-newbie-questions/#findComment-132728
Share on other sites

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 results
if(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]
Link to comment
https://forums.phpfreaks.com/topic/28974-newbie-questions/#findComment-132733
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.