<?php
die;
set_time_limit(0);
ini_set('memory_limit','1024M');
ini_set('post_max_size','32M');
ini_set('upload_max_filesize ','32M');

$destdir  = "live-data-migration-csvs/";
$name     = "resource_code.csv";
$destfile = $destdir.$name;  

$batch_size = 3000;
$table_name = "station_detail_table";
$records_inserted = 0;
$records_updated = 0;  
                                   
$flag = true;
$fp = fopen($destfile, 'r');
while (!feof ($fp)){
  $buffer = fgetcsv($fp, 1000000, ',');  
  if($flag) { 
	  if($buffer){
		$variable_array = array("Resource_Code","Resource_Description","Resource_Group_Code","Resource_Group_Description","type");

foreach($variable_array as $key=>$val){		
    ${$val} = addslashes(trim(strtolower($buffer[$key])));
}

if ($Resource_Code == "Resource_Code") {
    continue;
}

// use the $type variable here
$machine_type = utility::getTableFieldById(
    "station_master_table",    // table name
    "machine_type",            // field to get
    "station",                 // lookup field
    $type                      // lookup value
);
$station_id = utility::getTableFieldById(
    "station_master_table",    // table name
    "id",            // field to get
    "station",                 // lookup field
    $type                      // lookup value
);

			

			
			$records_inserted++;
			$sql =  "INSERT INTO $table_name(`station_id`,`resource_code`,`resource_description`,`resource_group_code`,`resource_group_description`,`machine_type`,`no_of_table`) VALUE('$station_id','$Resource_Code','$Resource_Description','$Resource_Group_Code','$Resource_Group_Description','$machine_type','1')";
			
			mysqli_query($conn,$sql);
	  }
  }
}
?>
<?php 
if($records_inserted){    
  echo '<br><span style="font-family:calibri;color:red;">'.($records_inserted).' records has been inserted...</span>';
}?>
 <?php 
if($records_updated){    
  echo '<br><span style="font-family:calibri;color:red;">'.($records_updated).' records has been updated...</span>';
}?>