Skip to content
Advertisement

How to insert array values to different MySQL column

I have an array that contains multiple images directory that I defined as $multipleDir.

Also I have table named product that contains the following structure:

JavaScript

$multipleDir contains 6 different images directory. My goal is to insert to each image column his own directory from the array.

Meaning:

JavaScript

My Insert code:

JavaScript

Each “test” represent image directory I want to apply.

I tried following the logic of foreach but it seems like the wrong approach because I can’t control which value will be contained on each column.

How can I insert array values to different MySQL column?

My foreach approach:

JavaScript

Advertisement

Answer

Remove foreach and just use $multipleDir array by $multipleDir[0]…$multipleDir[5]

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement