-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.

2
  • stackoverflow.com/questions/19077724/… Commented Mar 24, 2014 at 15:33
  • i'm sorry still very confusing for me... i'm not very familiar with this type of code. Commented Mar 24, 2014 at 16:04

1 Answer 1

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)";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.