I have a website for my football team. I have some statistics and so on in there, for example how many games each player has played and so on.
What I would like, is for me to write in the names of every player in the game and then update the db table with +1 in matches
column for each player.
I just made a frontend with form fields like this:
<input type="text" name="playername[]"><br>
<input type="text" name="playername[]"><br>
...
and so on, for 14 players.
In the backend, I wrote this:
$jinput = JFactory::getApplication()->input;
$playername = $jinput->getString('playername');
foreach ($playername as $key => $k) {
$fields = array(
$db->quoteName('matches') . ' = ' . $db->quoteName('matches') . ' + 1 '
);
$conditions = array(
$db->quoteName('name') . ' = ' . $db->quote($k)
);
$query->update($db->quoteName('my_players'))->set($fields)->where($conditions);
$db->setQuery($query);
$results = $db->execute();
}
But it only adds 1 match to the first name in the list. I tried
echo $k;
and it prints out all of the names. Can you help me?