Update multiple columns with plus 1

by Daniel Jensen   Last Updated April 19, 2018 08:10 AM

I have a website for my footballteam. I have some statistics and so on in there, fx 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 with +1 in matches.

I just made a frontend 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 names. Can you help me?



Related Questions



Connection to database timingout

Updated June 18, 2015 23:04 PM

Advertisment Simultaneously in several web sites

Updated March 05, 2017 14:10 PM


Transform PHP SQL to Joomla SQL query

Updated April 01, 2016 08:04 AM