Actually iam having headers in two rows for some columns
Example:Iam having start time it is divided into hours and minutes
In first row it is having starttime
below the start time iam having hours and minutes in the next row in different columns

while bulkuploading this hours and minutes should be concatenated and should be inserted into starttime.

Can anyone help this

can anyone help me regarding this thanks in advance

you can handle this kind of scinario using flag variable. I have written logic from what I understood from your question.

flag =false
while(read row one by one)
{

    if (flag ==false)
    {
           read row first way
           flag =true; 
    }
    else
    {
       flag =false; 
       read row second way
       concat start time (hours and minutes)
       insert row (using varible assignened in first way and second way)
    }
unset(all variables)
}

It would be great if you show your input in table format here.

y u mentioned flag=0

function casedetails() {
        $data['error'] = '';    //initialize image upload error array to empty

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'csv';
        $config['max_size'] = '1000';

        $this->load->library('upload', $config);


        // If upload failed, display error
        if (!$this->upload->do_upload()) {
            $data['error'] = $this->upload->display_errors();
            $data['mainpage']='cases';
            $data['mode']='case';
            $this->load->view('includes/mainpage',$data);

        } else {
            $file_data = $this->upload->data();
            $file_path =  './uploads/'.$file_data['file_name'];

            if ($this->csvimport->get_array($file_path)) {
                $csv_array = $this->csvimport->get_array($file_path);
                foreach ($csv_array as $row) {
                    //                  $this->db->trans_begin();


                   $Hours=$this->input->post('Hours');
                        if($Hours<10)
                        {
                            $Hours="0".$Hours;
                        }
                   $Minutes=$this->input->post('Minutes');
                        if($Minutes<10)
                        {
                            $Minutes="0".$Minutes;
                        }
                   $StartTime=$Hours.":".$Minutes;

            $cases= array(

                    'start_time'=>$StartTime,


                    );
                    $this->cases_model->cases($cases);
                    //                    $this->db->trans_commit();
                }
                $this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
                redirect(base_url().'cases/index');

            }
            else
            $data['error'] = "Error occured";
//          $data['records']=$this->cases_model->getcases();
            $data['mainpage']='cases';
            $data['mode']='case';
            $this->load->view('includes/mainpage',$data);

        }
    }

Actually i used this code to for bulkuploading in this for insertinfg stat_time i used the concatenation code but while inserting it is inserting into database as zero.

  A|B  These are the letters present in our csv file  
Start Time      These is the column of first row
Hours|Minutes   These are the columns of second row which iam having                   in my csv file.

anyone can help me please

I mentioned flag =0 because
I guess your continues two rows on CSV combines one rocord for you
Am I right?
so to read two lines on csv I used flag=0, when falg is zero it will read first line and when flag is one it will read second line and will insert.

Copied my code above is it correct or should i need to chane because while uploading my csv file it is inserting as zero in the database so...

can u check this code which i mentioned

anyone there to help

Hi ashalatha, I gave you logic from what I understood. I tried to read your code, but did not get anything why happening so.
One solution is to debug the code while reading every line in the csv and print the values of hours, minutes and start time.

actually iam comparing the table column name with csv file header name and storing it in an array.
csvimport is my library function and the hours and minutes as iam concatenating them into starttime.

Hi,

Can you at least give us few lines of the CSV file. It is okay to change the data to something else as long as the structure is the same as the original.

I can't promise you with anything, but I need to see at least few entries on the CSV then I let you know if I can do anything about it. Else, I cannot draw any analysis about the hammer's effeciency without looking at the nail first.

how can i post the csv file

I just need 3 rows..

for example, the most common CSV file format are similar to this.

First row as column names with delimiter |

username | email_address | phone_no | status | hobbies |

after the first row, it will be followed by the entries with | delimiter. Hobbies with delimiter ,.

veedeoo | veedeoo@any_do_com | 000-000-0000 | active | scuba diving, skateboarding, rock concerts, playing ukelel, playing Les Paul electric guitar, pink floy riffs

Line 0 or first row are commonly written like that. The CSV file dumper can parse that and make them the column names.

my csv file will be in this format actually while attaching the file it is not uploading so i did this in this format.

         A            B|C              D|E|F 

1st row case_id start_time Location
2nd row hours|minutes inpatient|icu|office

$data['error'] = '';    //initialize image upload error array to empty

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'csv';
        $config['max_size'] = '1000';

        $this->load->library('upload', $config);


        // If upload failed, display error
        if (!$this->upload->do_upload()) {
            $data['error'] = $this->upload->display_errors();
            $data['mainpage']='cases';
            $data['mode']='case';
            $this->load->view('includes/mainpage',$data);

        } else {
            $file_data = $this->upload->data();
            $file_path =  './uploads/'.$file_data['file_name'];

            if ($this->csvimport->get_array($file_path)) {
                $csv_array = $this->csvimport->get_array($file_path);
                foreach ($csv_array as $row) {
                   $Hours=$this->input->post('Hours');
                        if($Hours<10)
                        {
                            $Hours="0".$Hours;
                        }
                   $Minutes=$this->input->post('Minutes');
                        if($Minutes<10)
                        {
                            $Minutes="0".$Minutes;
                        }
                   $StartTime=$Hours.":".$Minutes;

                   $Inpatient=$this->input->post('Inpatient');
                   $icu=$this->input->post('ICU');
                   $office=$this->input->post('Office');

            $cases= array(
                    'case_id'=>$row['CaseId'], 
                    'age'=>$a,
                    'start_time'=>$StartTime,
                    'location_inpatient'=>$Inpatient,
                    'location_ICU'=>$icu, 
                    'location_office'=>$office,


                    );
                    $this->cases_model->cases($cases);
                }
                $this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
                redirect(base_url().'cases/index');

            }
            else
            $data['error'] = "Error occured";
//          $data['records']=$this->cases_model->getcases();
            $data['mainpage']='cases';
            $data['mode']='case';
            $this->load->view('includes/mainpage',$data);

        }

This is the code which i written for uploading a csv file with mutiple row headers

in B|c
iam having starttime
for that start time downside iam having hours and minutes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.