Re: CSV TO MYSQL
| From: | Chris Hobbs | Date: | Tue, 28 Aug 2001 03:16:03 +0000 |
| Subject: | Re: CSV TO MYSQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11869@lists.php.net to get a copy of this message | ||
How about this:
<?php
$emailstring = "me@my.com;this@that.com;let@this.com";
@emails = explode(";", $emailstring);
foreach($emails as $email) {
echo "INSERT INTO news VALUES('$email');\n";
}
?>
Rupert wrote:
Ok, this is my issue - hope someone can help. Suppose I also need to get this out of the way too - I am a Newbie (god..I hate that word...but it's true.....grin!) Anyway, I have a list of email address that I want to dump into a database called (news) - eg. me@my.com this@that.com let@this.com there@here.com etc.. I separated them with (;'s) like so - me@my.com; this@that.com; let@this.com; there@here.com; etc.. (I suppose I could use commas instead - no prob there) This is what I want to accomplish: Each email address is a separate entry that needs to be downloaded into the database. Just like this: # -------------------------------------------------------- # # Table structure for table 'news' # CREATE TABLE news ( email char(255) NOT NULL, PRIMARY KEY (email), UNIQUE email (email) ); # # Dumping data for table 'news' # INSERT INTO news VALUES ( 'me@my.com'); INSERT INTO news VALUES ( 'this@that.com'); INSERT INTO news VALUES ( 'let@this.com'); INSERT INTO news VALUES ( 'there@here.com'); INSERT INTO news VALUES ( 'etc..'); ------------------------------------------------------------ I have a script that gets me to this point: INSERT INTO news VALUES (,"me@my.com"," this@that.com"," let@this.com","there@here.com","etc.."); But that is not what I want. I can attach the script for analysis or if anyone has a better idea. I would appreciated it very much. Thanks.. Rupert-- Chris Hobbs Silver Valley Unified School District Head geek: Technology Services Coordinator webmaster: http://www.silvervalley.k12.ca.us/~chobbs/ postmaster: chobbs@silvervalley.k12.ca.us