Re: INSERT Array Values into mySQL Table

From: Date: Wed, 02 May 2007 19:21:52 +0000
Subject: Re: INSERT Array Values into mySQL Table
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-254254@lists.php.net to get a copy of this message
On Wed, May 2, 2007 10:42 am, Rahul S. Johari wrote: > 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: > //note added arguments! > function pr1($var, $var2, $var3) { > foreach ($var as $k => $v) { > echo ³$k => $v²; echo "$var2[$k] $var3[$k]"; //DID YOU USE mysql_real_escape_string YET?! $query = "insert into whatever (v1, v2, v3) "; $query .= " values('$v', '$var2[$k]', '$var3[$k]') "; Or maybe $v is an array itself? //perhaps you want: list($v1, $v2, $v3) = each($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² > > > > > > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#254254) next »