Welcome Guest, Not a member yet? Register   Sign In
Codeigniter CSV file undefined index
#1

I'm trying to display the content of CSV file, using Codeigniter.
I used a library CSVReader (found here https://github.com/alemohamad/ci-csv-rea...Reader.php)
I got this error message :
A PHP Error was encountered Severity: Notice Message: Undefined index: head2

Here is my code. Please tell me what is wrong. Thanks

-- File contents

head1;head2
EBBST02;col
EBBST08;lad
EBBST12;vad
EBBST1;saz
EBBST19;xed
EBBSS28;red


--Controller


Code:
public function import(){
        $data = array();
        $memData = array();
        // If import request is submitted
        if($this->input->post('importSubmit')){
            // Form field validation rules
            $this->form_validation->set_rules('file', 'CSV file', 'callback_file_check');

            // Validate submitted form data
            if($this->form_validation->run() == true){

                // If file uploaded
                if(is_uploaded_file($_FILES['file']['tmp_name'])){
                    // Load CSV reader library
                    $this->load->library('CSVReader');

                    // Parse data from CSV file
                  // $csvData = $this->csvreader->parse_csv($_FILES['file']['tmp_name']);
                    $result =  $this->csvreader->parse_file($_FILES['file']['tmp_name']);
                    $data['csvDatadisp'] =$result;


            }else{
                $this->session->set_userdata('error_msg', 'Invalid file, please select only CSV file.');
            }
        }
        //redirect('uploadria');
        $this->load->view('chargement/ria.php', $data);
    }


--View

Code:
<!-- Data list table -->
        <table class="table table-striped table-bordered">
            <thead class="thead-dark">
                <tr>
                    <th>Header 1</th>
                  <th>Header 2</th>
                </tr>
            </thead>
            <tbody>
                <?php if(!empty($csvDatadisp)){ foreach($csvDatadisp as $index => $value){ ?>
                <tr>
                    <td><?php echo $value['head1'] ?></td>
                    <td><?php echo $value['head2'] ?></td>
                </tr>
                <?php } }else{ ?>
                <tr><td colspan="5">No row found...</td></tr>
                <?php } ?>
            </tbody>
        </table>
Reply


Messages In This Thread
Codeigniter CSV file undefined index - by Hyper-X - 05-27-2020, 01:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB