Update Db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Update Db

Post 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());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure I understand....

Code: Select all

UPDATE tableName SET fieldName = fieldName + 1 WHERE foo = 'bar'
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

ok and how do I do

Code: Select all

echo '$G' where 'Name' = 'PlayerName';
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post 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()); 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

'foo' is a string
`foo` is a field/table/database reference.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post 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());
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you need quotes around your values

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