Re: Concatenate PHP code into a string
| From: | franciccio | Date: | Mon, 28 Jun 2004 22:05:03 +0000 |
| Subject: | Re: Concatenate PHP code into a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189188@lists.php.net to get a copy of this message | ||
$query="INSERT"+" ";
for ($i=0;$i<sizeof($col);$i++) {
$query+=cols[$i]+" ";
}
$query+="comment INTO mytable SET";
for ($i=0;$i<sizeof($col);$i++) {
$query+=cols[$i]+"="+$cols[$i]+",";
}
Bye
Franciccio
"Abrea" <abrea@estudiobrea.com> ha scritto nel messaggio
news:WorldClient-F200406281631.AA31300006@estudiobrea.com...
> Dear List,
> How can I include a dynamically generated array:
> e.g. for($i=0; $i<sizeof($cols); $i++)
> { $cols[$i]= mysql_field_name($fields,$i); }
>
> into a MySQL insert query of the type:
> $sql= "INSERT cols[0],cols[1],cols[2], ..., comment
> INTO mytable SET
> cols[0]= '$cols[0]',
> cols[1]= '$cols[1]',
> cols[2]= '$cols[2]',
> cols[...]= '$cols[...]',
> comment= '$comment'";
>
> The number of $cols is different for each table.
> Thanks in advance for any help
>
> Alberto Brea