got problem. got form this
<input name="product[sub_name][]"> <input name="product[price][]"> <input name="product[random][]"> <input name="product[just_field][]"> i can add many blocks of form pressing "add more". recieving posta data stuff.
$field = $_post['product']; foreach ($field $key => $values) { foreach($values $value) { $key.' - '.$value; } } i need code insert multiple rows in database depending on posted rows. problem that, dont know how only, example, "price". goal insert data in database. hope guys understand logic.
here print_r output. can got more possibilities two
array ( [sub_name] => array ( [0] => new car [1] => new bike ) [standart_price] => array ( [0] => 100 [1] => 300 ) [cupon_price] => array ( [0] => 50 [1] => 200 ) [max_purchases] => array ( [0] => 1000 [1] => 100 ) )
you can more ordered result if re-organize array contain index first:
<input name="product[$index][sub_name]"> <input name="product[$index][price]"> <input name="product[$index][random]"> <input name="product[$index][just_field]"> each time add new product change index javascript, in way, when recieve data in php can like:
$products = $_post['product']; foreach ($products $product) { $sub_name = $product['sub_name']; $random = $product['random']; $just_field = $product['just_field']; $sql = "your sql query" $mysqli->query($sql); } maybe need little more work changing html indexes javascript code become more clear.
p.s. that's general idea, don't test it.
Comments
Post a Comment