1

I try to import my.csv file but I cannot upload file and find out my problem. No error show, if I print my code see all empty value don't show anything.

Here is my code:

public function load_data(){
    $result = $this->web->select();
//  print_r($result);exit;
      $output = '
       <h3 align="center">Imported User Details from CSV File</h3>
            <div class="table-responsive">
             <table class="table table-bordered table-striped">
              <tr>
               <th>Sr. No</th>
               <th>First Name</th>
               <th>Last Name</th>
               <th>Phone</th>
               <th>Email Address</th>
              </tr>
      ';
      $count = 0;
      if($result->num_rows() > 0)
      {
       foreach($result->result() as $row)
       {
        $count = $count + 1;
        $output .= '
        <tr>
         <td>'.$count.'</td>
         <td>'.$row->first_name.'</td>
         <td>'.$row->last_name.'</td>
         <td>'.$row->phone.'</td>
         <td>'.$row->email.'</td>
        </tr>
        ';
       }
      }
      else
      {
       $output .= '
       <tr>
           <td colspan="5" align="center">Data not Available</td>
          </tr>
       ';
      }
      $output .= '</table></div>';
      echo $output;
}


 public function import() {
    $file_data = $this->csvimport->get_array($_FILES["csv_file"]["tmp_name"]);
   foreach($file_data as $row){
     $data[] = array(
      'first_name' => $row["First Name"],
      'last_name'  => $row["Last Name"],
      'phone'   => $row["Phone"],
      'email'   => $row["Email"]
     );
  }
  $this->web->insert($data);
 }

How can I upload csv and xlsx file by using codeigniter in easy and simple way?

3
  • are you updating the details in database after that? Commented Sep 4, 2018 at 5:43
  • $this->web->insert($data); Commented Sep 4, 2018 at 6:06
  • possible duplicate link Commented Sep 4, 2018 at 7:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.