I am trying to insert post data inside a Joomla table. So within a loop I populate the query with the values of a decoded json but all the time I get this error: Column count doesn't match value count at row 1
Here is my code:
$columns = array('column1','column2','column3','column4');
$query = $db->getQuery(true);
foreach($arrayDecodedJson as $key => $value)
{
$query
->insert($db->quoteName('#__table_name_'))
->columns($db->quoteName($columns))
->values(implode(',', $db->quote($value)));
$db->setQuery($query);
$db->execute();
}
The $value is an array with values I want to insert into the already existed table.
The $arrayDecodedJson keys and the columns are the same.
The data after var_dump($arrayDecodedJson) are like:
array( 'key1'=>'value1','key2'='value2') , array( 'key1'=>'value3','key2='value4'),
... array( 'key1'=>'valueN','key2'='value'N)