first I hope You understand the question I made because I'm not English. I'm making simple football league table. So I want to record all the team's goal between home team and away team including the players assists, and own goals using PHP form. the problem is I want to SUBMIT them in ONE foreach() instead of foreach() for inserting the goals, foreach() for inserting the assists, and foreach() for inserting the own goals.
I have tried using foreach(), and I just only know that is for ONE indexed array variable or Associative Array;
The code of form input goals, asssists, and own goal (this is from JSON encode):
'.... <td><input class="goal-home form-control col-6" name="goal_home['+data.player[i].id_player+']" type="number" value="0"></td>'+
'<td><input class="assist-home form-control col-6" name="assist_home['+data.player[i].id_player+']" type="number" value="0"></td>'+
'<td><input class="owngoal-home form-control col-6" name="owngoal_home['+data.player[i].id_player+']" type="number" value="0"></td>'+ ....
The code for get the data from home team side:
$goal_home = $this->input->post('goal_home');
$assist_home = $this->input->post('assist_home');
$owngoal_home = $this->input->post('owngoal_home');
And i have tried to insert the data to database something like this:
//The code for inserting each player's goal
foreach ($goal_home as $goal => $val) {
$this->m->query("UPDATE tbl_player
SET goal = (goal + $val)
WHERE id_player = $goal
");
}
//The code for inserting each player's assist
foreach ($assist_home as $assist => $val) {
$this->m->query("UPDATE tbl_player
SET assist = (assist + $val)
WHERE id_player = $assist
");
}
//The code for inserting each player's own goals
foreach ($owngoal_home as $owngoal => $val) {
$this->m->query("UPDATE tbl_player
SET owngoal = (owngoal + $val)
WHERE id_player = $owngoal
");
}
but my expecting something like this (I know this is wrong):
foreach (($goal_home as $goal => $val1), ($assist_home as $assist => $val2), ($owngoal_home as $owngoal => $val3)) {
$this->m->query("UPDATE tbl_player
SET goal = (goal + $val1), assist = (assist + $val2) ,owngoal = (owngoal + $val3)
WHERE id_player = $goal
");
I know that was wrong but I don't know the best way to explain this, I've been searching this similiar problem, but no one can resolve or maybe I don't understand. Thank you