Jump to content

Updating problem with one record only..


ade2901

Recommended Posts

Hi all,

 

I have a form which allows the end user to input results of football games. When they do this the league table is updated. I have everything working correctly apart from one team that consistently doesn't work. It adds up everything correctly apart from gf (goals for) and ga (goals against).

 

results.gif

 

The team that is problematic is 'The Southfield'. If for example they won 2-0 in fixtureID 19 and then 3-0 in fixtureID 20, their goals for and goals against would remain at 0, yet their points, won, drawn and lost values would be 100% correct...

 

See below for the code used to determine the league table;

 


<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$div1Table = "";


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$submit = $_POST['submit'];
$fixtureID = $_POST['fixtureID'];
$teamAScore = $_POST['teamAScore'];
$teamBScore = $_POST['teamBScore'];
$teamAID = $_POST['teamAID'];
$teamBID = $_POST['teamBID'];


$limit = count($fixtureID);

$deleteQRY = mysql_query("DELETE from division1")or die(mysql_error());
$selectTeamIDName = mysql_query("INSERT INTO division1 (teamID, teamName) SELECT teamID, teamName FROM team")or die(mysql_error());

for($i=0;$i<$limit;$i++) {
    $fixtureID[$i] = mysql_real_escape_string($fixtureID[$i]);
    $teamAScore[$i] = mysql_real_escape_string($teamAScore[$i]);
    $teamBScore[$i] = mysql_real_escape_string($teamBScore[$i]);
$teamAID [$i] = mysql_real_escape_string($teamAID[$i]);
$teamBID [$i] = mysql_real_escape_string($teamBID[$i]);

    $query = "UPDATE fixture SET teamAScore=$teamAScore[$i], teamBScore=$teamBScore[$i] WHERE fixtureID = $fixtureID[$i]";

    if(mysql_query($query))
        echo "$i successfully updated.<br/><a href='div1Results.php'>Back to main page</a>";

	//If fixtures update then update league table

//UPDATING OF LEAGUE TABLE TAKES PLACE HERE************************************************

		if ($teamAScore[$i] > $teamBScore[$i])
		{

			//Team A update for team A win
			$teamAWin = "UPDATE division1 SET played=played+1, won=won+1, gf= gf+".$teamAScore[$i].", ga= ga+".$teamBScore[$i].", pts= pts+3 WHERE teamID=$teamAID[$i]";
		    $resultTeamA = mysql_query($teamAWin) or die( "$teamAWin: " .mysql_error( ) ); 

			//Team B update for teamB loss
			$teamBLoss = "UPDATE division1 SET played=played+1, lost=lost+1, gf=gf+".$teamBScore[$i].", ga=ga+".$teamAScore[$i]." WHERE teamID=$teamBID[$i]";
		    $resultTeamB = mysql_query($teamBLoss) or die( "$teamBLoss: " .mysql_error( ) );
		} else

		if ($teamAScore[$i] < $teamBScore[$i])
		{
			//Team A update for team A win
			$teamALoss = "UPDATE division1 SET played=played+1, lost=lost+1, gf=gf+".$teamAScore[$i].", ga=ga+".$teamBScore[$i]." WHERE teamID=$teamAID[$i]";
		    $resultTeamALoss = mysql_query($teamALoss) or die( "$teamAloss: " .mysql_error( ) ); 

			//Team B update for teamB loss
			$teamBWin = "UPDATE division1 SET played=played+1, won =won+1, gf=gf+".$teamBScore[$i].", ga=ga+".$teamAScore[$i].", pts=pts+3 WHERE teamID=$teamBID[$i]";
		    $resultTeamBWin = mysql_query($teamBWin) or die( "$teamBWin: " .mysql_error( ) );
		}else 

		if ($teamAScore[$i] == $teamBScore[$i])
		{
			//Team A update for team A win
			$teamADraw = "UPDATE division1 SET played=played+1, drawn=drawn+1, gf=gf+".$teamAScore[$i].", ga=ga+".$teamBScore[$i].", pts=pts+1 WHERE teamID=$teamAID[$i]";
		    $resultTeamADraw = mysql_query($teamADraw) or die( "$teamADraw: " .mysql_error( ) ); 

			//Team B update for teamB loss
			$teamBDraw = "UPDATE division1 SET played=played+1, drawn=drawn+1, gf=".$teamBScore[$i].", ga=".$teamAScore[$i].", pts=pts+1 WHERE teamID=$teamBID[$i]";
		    $resultTeamBDraw = mysql_query($teamBDraw) or die( "$teamBDraw: " .mysql_error( ) );
		}

    else
        echo "$i encountered an error.<br/>";
}  

// close connection
mysql_close();
?>

 

All help as to why the gf and ga columns aren't working for one specific team would be much appreciated.

 

Thanks in advance,

 

Aidan

Link to comment
https://forums.phpfreaks.com/topic/239544-updating-problem-with-one-record-only/
Share on other sites

if its working for all the other teams but 1 then i doubt its a problem with this code, but instead you might have made an error in the mysql DB.

 

1 thing though

 

havn't you missed out the gf+ and ga+ in the code below?

$teamBDraw = "UPDATE division1 SET played=played+1, drawn=drawn+1, gf=".$teamBScore[$i].", ga=".$teamAScore[$i].", pts=pts+1 WHERE teamID=$teamBID[$i]";

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.