codeigniter - Multi-dimensional array parsed from .csv ->commas causing mysql database insert issues -


I am using Codeigniter to parse an uploaded CSV file (which is a multi-dimensional array) in the database . I have tried to parse everything coma correctly, but the "id" column in mysql is less because it reads "text", and not "text, text, text". help!?

  * For reference: * print_r ($ data ['csvData']); Array ([category, id] = & gt; Array ([category, id] => text1, "text, text, text") [1] = & gt; Array ([category, id] = & gt; {Foreach ($ line as item $) {$ item = explosion (",", $ item), foreach ($ data ['csvData'] as $ line) {text2, "text, text, text" ; $ Results_array = array ('category' => $ item [0], 'id' = & gt; $ item [1]); $ This- & gt; Db- & gt; Set ($ results_array); $ This- & gt; Db- & gt; Insert ('Table', $ results_array); }}  

My unexpected guess:

$ Item = explosion (",", $ item); Explode is $ item which is text1, "text, text, text" , is not it? So this sees 4 commas, and it explodes. Therefore, $ item will be [0] "text1, $ item [1] will be" text " $ item [2] will be" lesson "And $ item [3] be" text ".

You can try to set your delimiter in CSV as something other than a comma,

Or you can insert other items before putting them in DB:

  $ item = explosion (",", $ item ); $ Id_insert = $ item [1]. $ Item [2]. $ Item [3]; // if you have ID Comma needs to be retained in: $ $ id_insert = $ item [1]. ','. $ Item [2]. ',' $ Item [3]; $ results_array = array ('category' = & gt; ; $ Item [0], 'id' = & gt; $ id_insert,); $ this- & gt; db- & gt; Set ($ results_array); $ this-> db- & gt; Insert ( 'Table', $ result_array);  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -