I have create a php function to import the CSV/Excel file in to MYSQL database via CodeIgniter.
- It will check whether there are duplicate rows of data in database,if yet,it will update the data, else it will insert the data my problem is when I update the CSV file and upload again,I get error of
Severity: Warning
Message: pathinfo() expects parameter 1 to be string, array given
Filename: core/Loader.php
Line Number: 759
this is my coding for import the CSV
class Upload_services extends CI_Model
{
function __construct()
{
parent::__construct();
}
function upload_sampledata_csv()
{
if(isset($_POST['submit']))
{
$fp = fopen($_FILES['userfile']['tmp_name'],'r') or die("can't open file");
while(($line = fgetcsv($fp, 10000, ",")) !== FALSE)
{
//check whether there are duplicate rows of data in database
$prevQuery = array(
'articleno' => $line[0],
'oldarticle' => $line[1],
'product_description' => $line[2],
'pro_type' => $line[3],
'cust_group' => $line[4] ,
'size' => $line[5] ,
'colour' => $line[6],
'output' => $line[7],
'process_description' => $line[8],
'material_part' => $line[9]
);
$where = array(
'articleno' => $line[0],
'process_description' => $line[8],
'material_part' => $line[9]
);
$q = $this->db->select("*")
->where($where)
->from('sindi_productprocess_temp');
$prevResult = $this->db->get();
if($prevResult->num_rows > 0){
//update process data
$set =array('output'=>$line[7]);
$where = array(
'articleno' => $line[0],
'process_description' => $line[8],
'material_part' => $line[9]
);
$query = $this->db->get_where('sindi_productprocess_temp', array('output ='=>$line[7]))->result();
}else{
$data = array(
'articleno' => $line[0],
'oldarticle' => $line[1],
'product_description' => $line[2],
'pro_type' => $line[3],
'cust_group' => $line[4] ,
'size' => $line[5] ,
'colour' => $line[6],
'output' => $line[7],
'process_description' => $line[8],
'material_part' => $line[9]
);
$data['crane_features']=$this->db->insert('sindi_productprocess_temp', $data);
}
}
fclose($fp) or die("can't close file");
}
}
}
this is my CSV file that not yet being update CSV file
I want to change output for AB02-OKE-01-09-Y0-001 from 500 to 200 for material_part=Top PVC Sheet-Left,and 300 for Top PVC Sheet-Right
when i change the code as below,it working but instead of updated the existing data,it insert the duplicate data
if($prevResult->num_rows > 0){
//update process data
$data = array(
'articleno' => $line[0],
'oldarticle' => $line[1],
'product_description' => $line[2],
'pro_type' => $line[3],
'cust_group' => $line[4] ,
'size' => $line[5] ,
'colour' => $line[6],
'output' => $line[7],
'process_description' => $line[8],
'material_part' => $line[9]
);
$set =array('output'=>$line[7]);
$this->db->where = array(
'articleno' => $line[0],
'oldarticle' => $line[1],
'product_description' => $line[2],
'pro_type' => $line[3],
'cust_group' => $line[4] ,
'size' => $line[5] ,
'colour' => $line[6],
'process_description' => $line[8],
'material_part' => $line[9]
);
$this->db->update('sindi_productprocess_temp',$set);