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
4Boredom
Forum Contributor
Posts: 176 Joined: Tue Nov 08, 2005 4:29 pm
Post
by 4Boredom » Wed Dec 13, 2006 11:03 pm
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());
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Dec 13, 2006 11:07 pm
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 » Thu Dec 14, 2006 12:11 am
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Dec 14, 2006 3:23 am
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 » Fri Dec 15, 2006 11:09 pm
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 » Fri Dec 15, 2006 11:17 pm
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());
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Dec 15, 2006 11:34 pm
'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 » Sat Dec 16, 2006 1:12 am
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());
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat Dec 16, 2006 1:15 am
you need quotes around your values
... WHERE `Name`= ' John Lauro' ") ..