Jump to content

looping through multipul arrays and inserting into SQL


Bifter

Recommended Posts

Hi,

 

I have a form that once submitted some of its result are stored in arrays, example:

 

(The form has multipul lines with the same input names)

 

<select name="product[]"> once submitted goes into $_GET['product']

 

if I do:

 

// Product ID's

foreach($_GET['product'] as $name => $prodvalue) {

print "$name : $prodvalue<br>";

}

 

the following is returned:

 

0 : 9

 

1 : 10

 

2 : 11

 

3 : 12

 

Aswell as the Product ID's I have 2 other form input structured the same way, so my question is how do I loop through each of the $_GET's ($_GET['product'], $_GET['linequantity'] and $_GET['lineprice']) to add each of them to multipul SQL table rows? Also there will be other records that need to be entered, but, these will be constant, so for instance, if 3 rows are to be added then the other records will be the same for each of the 3 rows.

 

Please help me, I'm goin' nuts!

 

B.

 

Your $name variable is actually the array key and it ties all the related values to each other. Inside your existing foreach(){} loop, you can reference the other values using -

 

$_GET['linequantity'][$name]

$_GET['lineprice'][$name]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.