visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: reading info into table


By: roe1and Great Britain  Date: 05/02/2008 11:06:13  English  Points: 20 Status: Answered
Quality : Excellent
i've been creating a lot of tables that get their content from uploaded textfiles. typically a textfile would look like this:

value1¬value2¬value3¬value4
value5¬value6¬value7¬value8

this works quite well because you can insert it line for line and explode the information at the ¬ and then you have your values to insert into fielda, fieldb, fieldc, fieldd. that is quite straight forward.

at the moment i'm looking at text files that look like this:

01 infromation
02 information
03 information
04 information
05 information
01 information
03 information
04 information
01 information
02 information
03 information

i would only be interested in the bits that start with 01 and 03 and would like to insert them into 2 fields in a table. at the moment i'm trying to load these into an array and then stick them into a query everytime the 03 comes up? any suggestions





By: VGR Date: 07/02/2008 08:44:20 English  Type : Answer
idea :

$fp=fopen('toto.csv','r'); // I voluntarily skip the required tests on returned values $complete=FALSE; while ($ch=fgets($fp)) do { $z=explode($ch,' '); // TAB character = #9 if ( ($z[0]=='01') or ($z[0]=='03') ) { // keep the line if ($complete) { // this means the OTHER element has already been found! // get second element if ($z[0]=='01') $val01=$z[1]; else $val03=$z[1]; // write to DB the memorized values $val01 and $val03 $complete=FALSE; } else { // so this is the FIRST element we need // get first element if ($z[0]=='01') $val01=$z[1]; else $val03=$z[1]; } } // else NOP, skip } fclose($fp); // done.




not tested but should work

Do register to be able to answer

EContact
browser fav
page generated in 88.313820 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page