Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Strider64

Thread: Using IF Statement from SELFPOST to send data to a database.

  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Using IF Statement from SELFPOST to send data to a database.

    Hi everyone, i am stuck on this problem for my assignment.
    I have a database table that consists of the number of games per round for NBA.
    I am meant to let the users tip for the team that they want to win according to whos playing.
    There are 9 games per round.
    I have user radio buttons to let the user tip who they want to win.
    There is also a Points difference input box where the user can put in the number the they think the winning team is going to win by.

    So for example, For Game 1 - LA Lakers(HOME) VS LA Clippers(AWAY). So the user picks LA Clippers and puts in 20point difference.

    Now i am meant to input this data in to a database table. So if the user picks the Home team to win, the Point Difference going into the database will be Positive, if the User picks the Away team to win, the Point Difference should submit in a negative number, so from above example, while inserting the game, i would insert -20 as the user's pick for game 1.

    I have no idea idea how to go about doing this, any help would be much appreciated.

    This is my code i have so far to list all the games and the teams involved.

    <?php
    $games = array();

    for($num = 1; $num <= 9; $num++)
    {
    $games[$num] = "<table border='1'><tr><b><h4>Game ".$num."</h4></b><th>Home</th><th>Draw</th><th>Away</th></tr>";
    }

    while ($row = mysql_fetch_array($rs))
    {
    for($num = 1; $num <= 9; $num++)
    {
    $games[$num] .=
    " <tr>
    <td><input type='radio' id='home".$num."' name='game".$num."' value='".$row['home'.$num]."' > ".$row['home'.$num]."</td>
    <td>Draw <br /><input type='radio' id='draw".$num."' name='game".$num."' value='0'></td>
    <td>".$row['away'.$num]."<input type='radio' id='away".$num."' name='game".$num."' value='".$row['away'.$num]."'></td>
    </tr>";
    }
    }

    for($num = 1; $num <= 9; $num++)
    {
    $games[$num] .= "</table> Point Difference: <input type='text' name='g".$num."diff' size=5 />";
    echo $games[$num];
    }

    ?>
    <br />
    <br />
    <input type="submit" value="Submit" id="submit"/>&nbsp;
    <input type="reset" value="Reset"/>

  • #2
    New Coder
    Join Date
    Dec 2011
    Posts
    87
    Thanks
    5
    Thanked 14 Times in 14 Posts
    First, I have to say is "Slow Down" for you're trying to do everything at once, take it in steps. For example if I was doing this I would first setup how I would want my database table to be structure. For example, I might have id int(3), home_team varchar(15), away_team varchar(15) , point_diff int(4), and date_played timestamp. Then I would have my HTML forms setup in the body and I would have most of my PHP code separate from the HTML (on top is where I usually put it). My suggestion to you is get an updated PHP book that covers mysqli or PDO (My recommendation) for mysql is depreciated. ( I recommend author Larry Ullman and make sure the book for beginners, but there are other good php authors).
    chrishirst likes this.
    True courage is about knowing not when to take a life, but when to spare one. PDO Tutorial

  • #3
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Strider64 View Post
    First, I have to say is "Slow Down" for you're trying to do everything at once, take it in steps. For example if I was doing this I would first setup how I would want my database table to be structure. For example, I might have id int(3), home_team varchar(15), away_team varchar(15) , point_diff int(4), and date_played timestamp. Then I would have my HTML forms setup in the body and I would have most of my PHP code separate from the HTML (on top is where I usually put it). My suggestion to you is get an updated PHP book that covers mysqli or PDO (My recommendation) for mysql is depreciated. ( I recommend author Larry Ullman and make sure the book for beginners, but there are other good php authors).
    The table for the home team and away team is already there. All tables are there, we just need to populate them. We currently need to use mysql as thats what we have been taught, i know its outdated but thats what they have taught us.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,290
    Thanks
    23
    Thanked 611 Times in 610 Posts
    First your posted code wont work the way you think it will. An example is the way your assigning IDs.
    PHP Code:
    id='home".$num."' 
    Try this and see what you get
    PHP Code:
    <?php
    PHP Code:
    $num 4;
    echo 
    'home".$num."';
    ?> 
    Then this:
    PHP Code:
    <?php
    $num 
    4;
    echo 
    "home$num";
    ?>
    I think you need 3 tables. one for the team names, one for the keeping track of the winning teams, and one for the betters.

    You need to know the round and the game to id individual games.
    In the betters table need round - game - betters' name - team he picked - spread if he picked one or zero if he didn't - to make things easy a win/loss and maybe actual spread.
    winning team table need round - game - team name of winner.
    team name table just needs the team name and a number.
    You can assign the games but following something like this
    team | first round | second round | third round
    1----------4------------------3--------------2
    2----------1------------------4--------------3
    3----------2------------------1--------------4
    4----------3------------------2--------------1
    Hope this makes sense to you. At lest try to use the team name and generate the betting page.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •