I don't see the problem. If you have a table with 120 columns and
need to populate it, do you not want to do it with one insert
statement? What else?
I am not very familiar with perl, but in php it would be easy for
me to construct the insert statement:
You can read the columns names into one array; the values are in
the array $HTTP_POST_VARS; so you loop over the arrays and build
parts of your insert statement -- you only have to make sure you
get the correspondence correct.
If you name the columns accordingly, you don't even have to ask
mysql about them. So you say:
$q = 'INSERT INTO table (';
for ($i = 1; $i < 120; $i++) {
$q .= 'Q' . $i . ', ';
}
$q = substr($q, 0, -2);
//take off the last ', '
$q .= ') VALUES (';
while(list(, $val) = each($HTTP_POST_VARS)) {
$q .= "'$val', ";
}
$q = substr($q, 0, -2);
//take off the last ', '
$q .= ')';
//you are done, hoopefully, with something like
//INSERT INTO table (..., ...) VALUES ('...', ...)
Nelson Goforth schrieb am Dienstag, 31. Juli 2001, 20:47:31:
> In my application I'm writing up to 120 fields of data in one swoop
> (the results of a sort of survey). I'm using Perl DBI with MySQL.
> Each survey has several fields of data like 'name' (stored as
> parameters in the CGI object $asmt) and then up to 100 actual survey
> questions (Q1, Q2, etc). Until now I've just written one line of
> data to a text file, like:
> # Write basic data
> print FILE asmt -> param('name') . "\t";
> print FILE asmt -> param('city') . "\t";
> $v = 1;
> #write response to each question (Q1, Q2 etc)
> while ($v <= $questions) {
> $x = "Q" . $v;
> print FILE $asmt -> param($x). "\t";
> $v++;
> }
> And this works fine for the text file - but from what I've seen I
> probably can't carry over the iteration through the (up to) 100
> actual survey questions. I named the MySQL fields 'q1', 'q2',
> anticipating some way to do a loop, but I can't see it.
> Does anyone have any suggestions of how best to do this? The thought
> of one huge INSERT statement makes my eyes glaze over - I'm hoping
> there is a more elegant alternative.
> Thanks,
> Nelson
--
Herzlich
Werner Stuerenburg
_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.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 <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php