|
-
Tiger Shark
an update script for php/mysql
hi,
i am creating an interface for my baseball team to allow our coach to enter in our at bats and our hits.
i want it to pull the previous number for each batter out of the db, add the number of at bats and hits to it and then update the corresponding cell for that player
sorta like:
SELECT from BATTERS where name=$batter
$atbats = $abs +$currentatbat
$hits = $basehits =$currenthits
and that's about as far as i get. i can't figure out how to update the cells.
-
Hammerhead Shark
Check out the UPDATE syntax: http://www.mysql.com/doc/en/UPDATE.html
You would probably do something along the lines of:
PHP Code:
UPDATE batters SET atbats=$atbats, hits=$hits WHERE name=$batter
Although you may want to use a unique key for batters, otherwise no two batters can have the same name since it wouldn't be unique.
-
Tiger Shark
ah...so in that case i'd be better off using their numbers as the key. good idea.
-
Keys
I wouldn't use their number as a key since numbers get reused and you might want to reuse the database at some point and keep old data. Like if one year joe, player #42 leaves and someone else gets his old number, now you have to edit your DB and you will permanately lose Joe's stats. Probably good idea to use autonumber for a primary key in this case.
--------------------
When you were born you cried and the world smiled. Live your life so that when you die you smile and the world cries.
-
Hammerhead Shark
Yes like Begby said you should use an autonumber. There is no pressing reason why you want to do otherwise, and chances are #42 will be gone eventually (or any other number obviously).
-
Old School OCer
A better key would be playerNumber and playerName. That way you can retain history should someone return with their old number. I'd also add 'year' to the row.
The Money Trap = Intel i7 930 | Corsair H70 | ASUS P6X58D-E | 3 x 2GB G.Skill DDR3 2000 6-9-6-24 | EVGA GTX 580 DS SC | OCZ Vertex 2 90GB SSD | WD VelociRaptor | Klipsch ProMedia | Cooler Master HAF 932 | Antec TPQ-1200W | Dell U2711 2560 x 1440 27" | Windows 7 Ultimate 64-bit | APC RS1500
-
Ursus Arctos Moderatis
And if you wanted to take it one step further, an even more flexible design would seperate the "team-number" as an entity on to its own. That way relationships could exist between numbers, and players in a many-to-many fashion, and those relationships would probably be best defined with a time-span.
That would be a more normalized approach than the compound-key OS-Wiz suggested, since a compound-key would demand that player "X" have his profile repeated for every team-number he needed to be related to.
But I'm guessing this isn't some enterprise database you're designing - so I'd have to think that a more simple, but less flexible design would be your best option here.
-
Tiger Shark
thanks guys...i should've known i was over my head when i hunted on the web and couldn't find one script anywhere that dealt with baseball stats using mysql.
and the ideas about teams and years is a good idea but the whole purpose of this is to simplify the computation of our batting averages for display on our website.
no one had really planned on keeping these stats from year to year but that is a valid concern and i think i need to keep that in mind.
i like the year/number as the key...ie i'm #21 and this is 03 so i'd be 0321.
the displayed table will show, picture, number, name, position(s), and batting average.
also i've never done pictures via a db. should i try it via php/mysql of just use a regular html line for that?
fwiw...my wife calls this "little league for old men"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|