An Table with 100 cols, should not be handled by hand.In most cases is something forgotten. On Changes you have heavy task to find in code the Positions
Basically us the JForm with the correct Data-Definition (validation) and an JTable object that is connected with the table .. it prevents from a lot of errors ;-)
<?php
/** Example peace to get the Correct Columns**/
// Make sure, you have correct reflected and represented table columns
$existingColumns = array();
$table = JTable::getInstance('TableFileName', 'Prefix');
$table->reset()
if ($table instanceof JTable) {
$existingColumns = array_keys($table->getFields());
}
// we only want use this columns
$wantedColumns = array('col1', 'col2', 'col3');
/**
* Working with checked and save existing columns
**/
$arr = array('ARI', 'ATL');
// try this
$columns = $existingColumns;//array('col1', 'col2', 'col3');
// or this
$selectiveColumns = array();
foreach ($wantedColumns as $idx => $columnName) {
if (in_array($columnName, $existingColumns, true)) {
$selectiveColumns[] = $columnName;
}
}
$db = JFactory::getDbo();
foreach ($arr as $key => $value) {
$values = array($val1, $val2, $val3);
$query = $db->getQuery(true);
$query->insert($db->quoteName('#__tbname'))
->columns($db->quoteName($columns))
// or selective checked Columns
// ->columns($db->quoteName($selectiveColumns))
->values(implode(',', $db->quote($values)));
$db->setQuery($query);
try {
$db->execute();
} catch (Exception $e) {
// for testing purposes let us know what happends
var_dump($e->getMessage());
}
}
// Alternate you can use save the JTable as it self
// generic data
$dataStack =
array(
array('col1' => 'data'),
array('col1' => 'dataX'),
array('col1' => 'dataY'));
$table = JTable::getInstance('TableFileName', 'Prefix');
foreach ($dataStack as $data) {
$table->reset();
$table->bind($data);
$table->store();
}