Jump to content

[SOLVED] League Table script help?


Mr Chris

Recommended Posts

Hi Guys,

 

I'm in the process of putting together a script which you enter football results for, and depending on the results you put in this updates the league table accordingly below:

 

http://www.slougheaz.org/football/tables/premiership.php

 

Now here is where I enter my results to update this table:

 

http://www.slougheaz.org/football/admin/premiership_results.php

 

Now this system works:

 

If:

 

Team 1 score > Team 2

Team 1 score == Team 2

 

BUT

Team 1 score < Team 2

 

(please feel free to try this yourself)

 

An error is produced.  Now I think there is something wrong with my code here

 

} else if($team_1_score < $team_2_score) {  
  $result = " 
            update league_table set 
league ='p',
            team_losses=team_losses+1,  
            team_gf=team_gf+'$team_1_score', 
            team_ga=team_ga+'$team_2_score' 
            where 
            team_name='$team_1'"; 
            $result2 = "update 
            league_table set 
league ='p',
            team_wins=team_wins+1, 
            team_gf=team_gf+'$team_2_score', 
            team_ga=team_ga+'$team_1_score', 
team_points_total=team_points_total+3
            where team_name='$team_2'";

 

And here's my full code as I was a bit vague before:

 

<?php

if(isset($_POST['formsubmit'])) { 
    # insert the result into the table 
    $team_1 = $_POST['team_1']; 
    $team_1_score = $_POST['team_1_score']; 
    $team_2 = $_POST['team_2']; 
    $team_2_score = $_POST['team_2_score']; 
        if(!mysql_query("insert into results (team_1, team_1_score, team_2, team_2_score, result) values ('$team_1', '$team_1_score', '$team_2', '$team_2_score', '')")) { 
        echo 'oops '.mysql_error(); 
        } 
        # start calculations 
        if($team_1_score > $team_2_score) { 
            $result = " 
            update league_table set 
league ='p',
            team_wins=team_wins+1, 
            team_gf=team_gf+'$team_1_score', 
            team_ga=team_ga+'$team_2_score', 
            team_points_total=team_points_total+3 
            where 
            team_name='$team_1'"; 
            $result_2 = "update 
            league_table set 
league ='p',
            team_losses=team_losses+1, 
            team_gf=team_gf+'$team_2_score', 
            team_ga=team_ga+'$team_1_score' 
            where team_name='$team_2'"; 
            } else if($team_1_score < $team_2_score) {  
            $result = " 
            update league_table set 
league ='p',
            team_losses=team_losses+1,  
            team_gf=team_gf+'$team_1_score', 
            team_ga=team_ga+'$team_2_score' 
            where 
            team_name='$team_1'"; 
            $result2 = "update 
            league_table set 
league ='p',
            team_wins=team_wins+1, 
            team_gf=team_gf+'$team_2_score', 
            team_ga=team_ga+'$team_1_score', 
team_points_total=team_points_total+3
            where team_name='$team_2'"; 
            } else if($team_1_score == $team_2_score) { 
            $result = " 
            update league_table set 
league ='p',
            team_draws=team_draws+1, 
            team_gf=team_gf+'$team_1_score', 
            team_ga=team_ga+'$team_2_score', 
            team_points_total=team_points_total+1 
            where 
            team_name='$team_1'"; 
            $result_2 = " 
            update league_table set 
league ='p',
            team_draws=team_draws+1, 
            team_gf=team_gf+'$team_2_score', 
            team_ga=team_ga+'$team_1_score', 
            team_points_total=team_points_total+1 
            where 
            team_name='$team_2'"; 
            } 
            if(!mysql_query($result)) { 
                echo 'oops again '. mysql_error(); 
                } 
            if(!mysql_query($result_2)) { 
                echo 'oops again 2 '. mysql_error(); 
                } 
                echo $team_1 . ' ' . $team_1_score .' VS '. $team_2 . ' ' . $team_2_score; 
} 
?> 
<html> 
<head> 
<title>Teams</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 

<body> 
<form name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<dl> 
    <dt>Team 1</dt> 
    <dl><select class="input" name="team_1" size="1" tabindex="1"> 

      <option value="" selected>Teams</option> 

        <?php 

          $type_array=get_premiership_teams(); 

          foreach ($type_array as $teams) 

          { 

          print("<option value=\"".$teams['team_name']."\">".$teams['team_name']."</option>\n"); 

          } 

        ?>

    </select>
    </dl> 
    <dt>Team 1 score</dt> 
    <dl><input name="team_1_score" type="text" size="5"> 
    </dl> 
    <dt>Team 2</dt> 
    <dl><select class="input" name="team_2" size="1" tabindex="1"> 

      <option value="" selected>Teams</option> 

        <?php 

          $type_array=get_premiership_teams(); 

          foreach ($type_array as $teams) 

          { 

          print("<option value=\"".$teams['team_name']."\">".$teams['team_name']."</option>\n"); 

          } 

        ?>

    </select></dl> 
    <dt>Team 2 score</dt> 
    <dl><input name="team_2_score" type="text" size="5"> 
        <input type="hidden" name="formsubmit"> 
    </dl> 
</dl> 
<input type="submit" name="submit" label="submit"> 
</form> 
</body> 
</html>

 

Anything wrong with my queries or code?

 

Thanks

 

Chris

 

Link to comment
https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/
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.