-2

i have the following code:

 $var1="bmx"
 $newdata = implode(",", $dx);
 $queryinsert = "INSERT INTO table VALUES ($var1,$newdata)";

but with this code i get some like

INSERT INTO table VALUES (bmx,black,white, green, yellow,grey)";

and i need to create a new row for each color, like

INSERT INTO table VALUES (bmx,white)";
INSERT INTO table VALUES (bmx,black)";etc...

i think i should use a foreach but i don't know how.

1 Answers1

0

You need something like this. Go to the php docs, you will find everithing there.

$var1="bmx"

foreach ($dx as &$value) {
   $queryinsert = "INSERT INTO table VALUES ($var1,&$value)";
}
PeterRing
  • 1,767
  • 12
  • 20