Note that there are some explanatory texts on larger screens.

plurals
  1. POFgetcsv with loop and get the correct value
    primarykey
    data
    text
    <p>I have a txt file and I need to upload it in my mysql db. So I found this code in php.net:</p> <pre><code>$row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "&lt;p&gt; $num fields in line $row: &lt;br /&gt;&lt;/p&gt;\n"; $row++; for ($c=0; $c &lt; $num; $c++) { echo $data[$c] . "&lt;br /&gt;\n"; } } fclose($handle); } </code></pre> <p>It worked. When I gave a 'print_r' I have this:</p> <pre><code>PAGE:1 ANUALDATA Ver:1.651.A Site data ou www.sitedata.com COUNT:3758-3 NAME:USER NAME IDUS: 262.911.258-62 PLACE:030 IDCUS:11003 DATE 31/12/2011 VALUE................................U$ 200,00 PROCESS DATE 31/12/2011 VALUE NEEDED.....................U$ 3,45 PAID VALUE..........U$ 50,00 PAGE:2 ANUALDATA Ver:1.651.A Site data ou www.sitedata.com COUNT:3758-3 NAME:USER NAME IDUS: 262.911.258-62 PLACE:030 IDCUS:11003 DATE 31/12/2011 VALUE................................U$ 200,00 PROCESS DATE 31/12/2011 VALUE NEEDED.....................U$ 3,45 PAID VALUE..........U$ 50,00 PAGE:3 ANUALDATA Ver:1.651.A Site data ou www.sitedata.com COUNT:3758-3 NAME:USER NAME IDUS: 262.911.258-62 PLACE:030 IDCUS:11003 DATE 31/12/2011 VALUE................................U$ 200,00 PROCESS DATE 31/12/2011 VALUE NEEDED.....................U$ 3,45 PAID VALUE..........U$ 50,00 </code></pre> <p>Now comes my problem. I saw others examples but really could use it into my case. I need to do something like transform each line in $key = $val, like</p> <pre><code>[VALUE] =&gt; 200,00 [PROCESS DATE] =&gt;31/12/2011 </code></pre> <p>And you will notice that are pages, I need to brake it to have something like this</p> <pre><code>[0] [VALUE] =&gt; 200,00 [PROCESS DATE] =&gt;31/12/2011 [1] [VALUE] =&gt; 200,00 [PROCESS DATE] =&gt;31/12/2011 </code></pre> <p>So, I will insert this data in each row in db. Is there a way? If I could get only de $value it will be ok too.</p> <p>Edit</p> <p>It is not an CSV, it is an TXT that another system creates and I don´t have control over it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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