--- Marian Briones <[EMAIL PROTECTED]> wrote:

> I want to be able to take a flat file that looks like this:
>
> [EMAIL PROTECTED]|Marian|Briones
> [EMAIL PROTECTED]|Bob|Smith
> [EMAIL PROTECTED]|Jane|Doe
> (etc)
>
> The table has more than 3 fields, so I'd want to process the flat file
> and then do an INSERT into mailinglist SET field=$value for each line.
>
> Does someone have a nice way for me to do this?  The flat file will be
> uploaded to the server via a form (copy) and then be processed.
>
> I've googled and can't find what I need.
>
> Thank you in advance,
> Marian

Basically you want to take each line and divide it up based on the "|" character.

$db = mysql_connect("localhost","dbuser","dbpwd");
mysql_select_db("dbname");
$input_file = file("filename.txt"); // puts each line into an array element
foreach($input_file as $line)       // loop through file array
{
list($email,$first,$last) = split("|",$line); // chop up line
$q = "INSERT INTO tablename SET email='$email', first='$first', last='$last'";
mysql_query($q, $db) or die("$q<hr>" . mysql_error());
}

This code is untested and you will have to modify it to meet your needs and situation.

James


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




Reply via email to