Page 1 of 1

Update Db

Posted: Wed Dec 13, 2006 11:03 pm
by 4Boredom
Im doing a site with baseball stats. I want them to be able to update each game the players stats but I dont want them overwritten. How do I edit this so that it does like a +1 for games but doesnt delete the previous games?

Code: Select all

$sql = "UPDATE 
                `offensive_stats` 
        SET 
                Games='$Games', AB='$AB', Runs='$Runs', Hits='$Hits', 
                2B='$B2', 3B='$B3', HR='$HR', RBI='$RBI', 
                BB='$BB', SO='$SO', CS='$CS', HBP='$HBP', 
                SAC='$SAC' 
        WHERE 
                Name='$Name'"; 
$query = mysql_query($sql) or die(mysql_error());

Posted: Wed Dec 13, 2006 11:07 pm
by feyd
I'm not sure I understand....

Code: Select all

UPDATE tableName SET fieldName = fieldName + 1 WHERE foo = 'bar'

Posted: Thu Dec 14, 2006 12:11 am
by 4Boredom
If I want to keep an average of say 3 columns... Games, At Bats, and Hits..... and have 5 games in the datebase.....

5 games
25 At Bats
8 Hits


And I want to add a 6th game with 5 at bats and 2 hits thru my update script

It should equal 6 games, 30 at bats 10 hits and not just the stats of the 6th game

How do I do this?

Posted: Thu Dec 14, 2006 3:23 am
by volka
feyd wrote:

Code: Select all

UPDATE tableName SET fieldName = fieldName + 1 WHERE foo = 'bar'
That doesn't only work for one field but -if you like- for all fields of a record.
games=games+1, bats=bats+5, hits=hits+2

Posted: Fri Dec 15, 2006 11:09 pm
by 4Boredom
ok and how do I do

Code: Select all

echo '$G' where 'Name' = 'PlayerName';

Posted: Fri Dec 15, 2006 11:17 pm
by 4Boredom
Im trying this but it doesnt work...

Code: Select all

<?
$display= mysql_query("SELECT 'G' FROM 'offensive_stats' WHERE 'Name'=John Lauro"); 
$result= mysql_query($display) or die ($ERROR_MSG . mysql_error()); 
?>

Posted: Fri Dec 15, 2006 11:34 pm
by feyd
'foo' is a string
`foo` is a field/table/database reference.

Posted: Sat Dec 16, 2006 1:12 am
by 4Boredom
This displays the same result :(

Could not get user info

Code: Select all

$display= mysql_query("SELECT `Games` FROM `offensive_stats` WHERE `Name`=John Lauro"); 
$result= mysql_query($display) or die ($ERROR_MSG . mysql_error());

Posted: Sat Dec 16, 2006 1:15 am
by John Cartwright
you need quotes around your values

... WHERE `Name`= 'John Lauro'") ..