Emma Grant wrote:
>Hi,
>
>Does anyone know how to separate values in a text area field, to enter
>the separated values into a database?
>
>For instance if enter these values into a text area field
>
>Dogs
>Cats
>Fish
>
>I want to be able to take Dogs, Cats and Fish and put them in different
>rows in a database. I guess the biggest problem I have is splitting the
>values in the text area field that is separated by a carriage return.
>Once I have that, and I know how to separate the values, then I can
>easily put them into a database.
>
>BTW I am using CGI/PERL to enter the values into a MySql database.
>
>
>
#!/usr/bin/perl -w
#
# filename: test.pl
#
my $rowcnt = 0;
my $q;
$q = "INSERT INTO tab VALUES ("
while (<>) {
chomp();
$q .= "'".$_."',";
}
chop($q);
$q .= ")"
print $q."\n";
######
sh -c test.pl < -
Dogs
Cats
Fish
^D
This would print something like:
INSERT INTO tab VALUES ('Dogs','Cats','Fish')
Greetings
Ralf
>
>
sql, query
--
Ralf Narozny
SPLENDID Internet GmbH & Co KG
Skandinaviendamm 212, 24109 Kiel, Germany
fon: +49 431 660 97 0, fax: +49 431 660 97 20
mailto:[EMAIL PROTECTED], http://www.splendid.de
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php