lucy Posted August 26, 2009 Share Posted August 26, 2009 How can i create a form, which when an integer is inputted, it ads the value of this, to the previous records same value? For example, if i was to create a database to record number of goals in the season (lame i know!). after each game i would enter how many goals i had scored that day, and adding them to the total number of goals for the season? Thanks, Lucy Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/ Share on other sites More sharing options...
asmith Posted August 26, 2009 Share Posted August 26, 2009 UPDATE tableOfRecords SET numberOfGoalsField = numberOfGoalsField + DailyGoals WHERE MEMBER = 'YOU' Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-906636 Share on other sites More sharing options...
lucy Posted August 26, 2009 Author Share Posted August 26, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-906650 Share on other sites More sharing options...
lucy Posted August 26, 2009 Author Share Posted August 26, 2009 I thought it was solved but its not. I know how to increment the total number of goals scored but it changes the value for the previous total number of goals scored after each game to the current total number of goals. I need the database to show the total number of goals for the game were adding and all previous ones e.g.: game 0 goals scored=0 total number=0 game 1 goals scored= 3 total number = 3 game 2 goals scored=1 total number = 4 game 3 goals scored =0 total number = 4 e.t.c. but what im getting is the total number of goals in all records is set to the current toal e.g. game 0 goals scored = 0 total number = 4 game 1 goals scored = 3 total number = 4 game 2 goals scored = 1 total number = 4 game 3 goals scored = 0 total number = 0 How can i make it so the total number of goals, for each record, is the sum of the goals scored for this record + the total number of goals for the previous record? the code i have at the moment: $user=BLANK $password=BLANK $database=BLANK //connect to the database $con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error()); //select the database mysql_select_db($database, $con); $goals= $_POST[goals]; mysql_query("INSERT INTO table1 VALUES ('','','','','','','$_POST[goals]','','','')") or die('Error: ' . mysql_error()); mysql_query("UPDATE table1 SET total_goals= total_goals + $goals"); Thanks for any help Lucy Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-906755 Share on other sites More sharing options...
lucy Posted August 26, 2009 Author Share Posted August 26, 2009 Anybody have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-907121 Share on other sites More sharing options...
lucy Posted August 26, 2009 Author Share Posted August 26, 2009 Ive done it now. I had an auto increment field in the table so i did it the following way: $goals= $_POST[goals]; $query= mysql_query("SELECT total_goalsFROM table1 ORDER BY number DESC LIMIT 1"); $goals1 = mysql_fetch_array( $query); $goals2 = $time1['total_goals']; $new_total_goals= $goals+ $goals; Thanks, Lucy Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-907139 Share on other sites More sharing options...
asmith Posted August 27, 2009 Share Posted August 27, 2009 Have you succeed on what you wanted to do? Cause your code seems to be wrong. Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-907260 Share on other sites More sharing options...
lucy Posted August 27, 2009 Author Share Posted August 27, 2009 It works yes how would you have done it? Thanks, Lucy Quote Link to comment https://forums.phpfreaks.com/topic/171944-solved-increment-field-by-input-value/#findComment-907475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.