Welcome Guest, Not a member yet? Register   Sign In
CSV upload, once uploaded to a temp folder overwrite the existing database
#19

[eluser]the_unforgiven[/eluser]
Well this is what i have at present and works just fine, except it throws SQL error because there's some apostrophes in the content

Code:
$data = file_get_contents("http://localhost/sussex/assets/uploads/wc_program.csv");
  
   //Explode the csv into an array of lines
   $lines = explode(",", $data);
    
   $file_handle = fopen("http://localhost/sussex/assets/uploads/wc_program.csv", "r");

  
   while (($line_of_data = fgetcsv($file_handle, 1000, ",")) !== FALSE)
   {

          $line_import_query="INSERT INTO wc_program_temp (JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish) values(
           '$line_of_data[0]',
           '$line_of_data[1]',
           '$line_of_data[2]',
           '$line_of_data[3]',
           '$line_of_data[4]',
           '$line_of_data[5]',
           '$line_of_data[6]',
           '$line_of_data[7]',
           '$line_of_data[8]',
           '$line_of_data[9]',
           '$line_of_data[10]')";

        //mysql_query($line_import_query) or die(mysql_error());
         if ($this->db->query($line_import_query))
     {
       $this->load->view('program/success');
     }
     else {
      echo "Failed";
     }

       }


Messages In This Thread
CSV upload, once uploaded to a temp folder overwrite the existing database - by El Forum - 03-24-2013, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB