I want to import sing column of excel sheet into database table name admin_record and excel sheet is only consist of one column and name of the column is bar codes and rows can be many.
I want to save it in database my table name is admin_record and its consists of only two fields
- id (which is primary key)
- bar_code.
find only this code which i totally cant understand
public function read_file($table = 'admin_record', $filename = 'example.xls') {
$pathToFile = 'uploads/' . $filename;
$this->load->library('Spreadsheet_Excel_Reader');
$data = new Spreadsheet_Excel_Reader($pathToFile);
$sql = "INSERT INTO $table (";
for($index = 1;$index <= $data->sheets[0]['numCols']; $index++){
$sql.= strtolower($data->sheets[0]['cells'][1][$index]) . ", ";
}
$sql = rtrim($sql, ", ")." ) VALUES ( ";
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$valuesSQL = '';
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$valuesSql .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\", ";
}
echo $sql . rtrim($valuesSql, ", ")." ) <br>";
}
}