RE: [PHP] INSERT Array Values into mySQL Table
| From: | Brad Fuller | Date: | Wed, 02 May 2007 15:53:24 +0000 |
| Subject: | RE: [PHP] INSERT Array Values into mySQL Table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254239@lists.php.net to get a copy of this message | ||
Rahul S. Johari wrote:
> Ave,
>
> Here¹s the thing, I¹ve got an Array which has it¹s own set of
> Keys => Values. I¹m using foreach() to read the Keys => Values like
> this:
>
> function pr1($var) {
> foreach ($var as $k => $v) {
> echo ³$k => $v²;
> }
>
> I need to INSERT the Values from this array into a mySQL
> table. The problem is, There is other data that is going into
> the same row of that mySQL Table as well.
>
> So I have to basically insert 3 fields and then the rest of
> values I have to insert using this Array. In other words, this is
> what I have to do:
>
> INSERT into table (f1, f2, f3, f4, f5) VALUES (Œ$1¹, Œ$2¹,
> Œ$3¹, //and the rest of the values from from the $v Values from that
> Array $var.....
>
> I¹m not able to formulate a code to do this. Any help would be really
> appreciated.
>
> Thanks.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Rahul Sitaram Johari
> CEO, Twenty Four Seventy Nine Inc.
>
> W: http://www.rahulsjohari.com
> E: sleepwalker@rahulsjohari.com
>
> ³I morti non sono piu soli ... The dead are no longer lonely²
$sql = "INSERT INTO table (f1, f2, f3, ". implode(",", array_keys($pr1))
.")
VALUES ('abc', '123', '456', ". implode(",",
array_values($pr1))
.")";
HTH,
Brad