Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is an easy way to do this. I don't know what people do but i use this</p> <p>This is my csv reader library </p> <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class CSVReader { var $fields; /** columns names retrieved after parsing */ var $separator = ';'; /** separator used to explode each line */ var $enclosure = '"'; /** enclosure used to decorate each field */ var $max_row_size = 4096; /** maximum row size to be used for decoding */ function parse_file($p_Filepath) { $file = fopen($p_Filepath, 'r'); $this-&gt;fields = fgetcsv($file, $this-&gt;max_row_size, $this-&gt;separator, $this-&gt;enclosure); $keys_values = explode(',',$this-&gt;fields[0]); $content = array(); $keys = $this-&gt;escape_string($keys_values); $i = 1; while( ($row = fgetcsv($file, $this-&gt;max_row_size, $this-&gt;separator, $this-&gt;enclosure)) != false ) { if( $row != null ) { // skip empty lines $values = explode(',',$row[0]); if(count($keys) == count($values)){ $arr = array(); $new_values = array(); $new_values = $this-&gt;escape_string($values); for($j=0;$j&lt;count($keys);$j++){ if($keys[$j] != ""){ $arr[$keys[$j]] = $new_values[$j]; } } $content[$i]= $arr; $i++; } } } fclose($file); return $content; } function escape_string($data){ $result = array(); foreach($data as $row){ $result[] = str_replace('"', '',$row); } return $result; } } ?&gt; </code></pre> <p>And controller method</p> <pre><code>function readExcel() { $this-&gt;load-&gt;library('csvreader'); $result = $this-&gt;csvreader-&gt;parse_file('Test.csv'); $data['csvData'] = $result; $this-&gt;load-&gt;view('view_csv', $data); } </code></pre> <p>And this is view</p> <pre><code>&lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tr&gt; &lt;td width = "10%"&gt;ID&lt;/td&gt; &lt;td width = "20%"&gt;NAME&lt;/td&gt; &lt;td width = "20%"&gt;SHORT DESCRIPTION&lt;/td&gt; &lt;td width = "30%"&gt;LONG DESCRIPTION&lt;/td&gt; &lt;td width = "10%"&gt;STATUS&lt;/td&gt; &lt;td width = "10%"&gt;PARENTID&lt;/td&gt; &lt;/tr&gt; &lt;?php foreach($csvData as $field){?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $field['id']?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $field['name']?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $field['shortdesc']?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $field['longdesc']?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $field['status']?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $field['parentid']?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php }?&gt; &lt;/table&gt; </code></pre> <p>Reference <a href="https://stackoverflow.com/questions/11337221/codeigniter-rest-csv-import-to-mysql/11339125#11339125">Here</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload