Thanks, James.

I actually found one that handed things beautifully, including
predefining my insert by grabbing the field names from the db table -
elminating the possibility of me making a typo in my insert code! 
I'll share:

    $fcontents = file ('textfile.txt'); 
//    $fcontents = "$import"; 
    # expects the csv file to be in the same dir as this script

      for($i=0; $i<sizeof($fcontents); $i++) 
      { 
          $line = trim($fcontents[$i]); 
          $arr = explode("|", $line); 
          #if your data is comma separated
          # instead of tab separated, 
          # change the '\t' above to ',' 
          # mine is | separated

          $sql = "insert into dbtable values (0,'". 
                      implode("','", $arr) ."')"; 
          mysql_query($sql);
          echo $sql ."<br>\n";
          if(mysql_error()) 
          {
             echo mysql_error() ."<br>\n";
          } 
        }

So it outputs what it did you can see the insert, then I made a link
on the "data updated" query to take me to the page that displays the data.

Cool beans!


--- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote:
>
> --- Marian Briones <[EMAIL PROTECTED]> wrote:
> 
> > Hi gang
> > I'm trying to export data from a pipe delimited file (|) with 
> > php, trying to get away from perl entirely.
> > 
> > My old perl script opens the file and sticks it in an array, 
> > then handles each line as a record in the database table by 
> > splitting the line like this:
> > 
> > ($MLSNo, $Status,  $DOM, $Address, $Unit, $City, $Area, $LP, 
> > $SP, $BT, $SqFt, $Bed, $Bth, $PB, $Gar, $Garno, $YrBlt, $TBMap, 
> > $Acres, $LotSqFt, $HOA, $Freq) = split (/\|/,$i);
> > 
> > How can I achieve the same with php??????
> 
> // place the contents of a file in an array (1 line per element)
> $array = file("filename");
> 
> // loop through each line of the file
> foreach($array as $line)
> {
> 
> list($MLSNo, $Status,  $DOM, $Address, $Unit, $City, $Area, $LP, 
$SP, $BT,
> $SqFt, $Bed, $Bth, $PB, $Gar, $Garno, $YrBlt, $TBMap,  $Acres,
$LotSqFt, $HOA,
> $Freq) = split("|", $line);
> 
> // do something with the variables
> 
> }
> 
> James
> _____
> 
> 
> James D. Keeline
> http://www.Keeline.com  http://www.Keeline.com/articles
> http://Stratemeyer.org  http://www.Keeline.com/TSCollection
> 
> http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
> Fall Semester Begins Sep 7 -- New Classes Start Every Few Weeks.
> Spring Semester Begins in late January.  Two new class topics.
>







Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to