Fairly new to php but know enough to be dangerous. I'm really stumped on this:

I have stat numbers already in database linked with an id and also created an add stats page. So when a user is on the add stats page they enter the specific id & new stats.

Questions is, once they click submit I need the new stats to add with stats already in database and show the combined stats on the page.

Hope that made sense, basically adding numbers already in database with new numbers coming in.

Any help would be much appreciate - thanks in advance

6 Years
Discussion Span
Last Post by Giggaman

Where is the problem?
You dynamic PHP page displays the database content.
When the user submits new stats, store it to the database first place in your script. Then load the data from the database and display the current database content - including the newly submitted data - in the same script.


Depends on the stats you need. MySQL can produce basic stats by combining values in certain ways, but complicated stats may be better left to php. Your DB should just store values - try to avoid storing intermediate calculated values. 'Stats' then are calculated on the fly (via query and/or subsequent php functions).

If you need to display updated stats after data input without reloading the page, have a look at Ajax.

Edited by diafol: n/a


Ok have a better understanding, the stats are very simple baseball.

What query would you use to add new stats to the database table & combine them to display.

- Example: id [18] has At Bats: 7 (this is already in the database)

- Add Page: user selects id [18] and enters At Bats: 4 (Post HTML Form) & clicks submit

- What query do you use for addition equation? How do you show At Bats: 11

Sorry if I sound like an idiot, hope your not laughing too much at me. Thanks in advance-


Does user login? If yes then when user logs in query his current stats into session. Then when he adds then by clicking a form submit, just take submitted value, add to session value and update database!

UPDATE table1 SET at_bats = at_bats + $newamount WHERE user_id = $id

Edited by diafol: n/a


@Ardav your making sense but have one last question, I have more than one record to add, lets say I have at_bats & hits, would the query look like:

UPDATE table1 SET at_bats = at_bats, hits = hits + $at_bats, $hits WHERE user_id = $id

Not sure how to separate records, yet keep them together. - Again Thanks in advance


One assignment for each field:

UPDATE table1 SET at_bats = at_bats + $at_bats, hits = hits + $hits WHERE user_id = $id;

@ smantscheff your a freaking genius!!!

@ ardav your a freaking genius !!!

Thanks for helping a beginner out, bravo!!!


Yes, my problem has been solved, able to add new input with database and display the updated stats. Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.