php - Storing array in multiple mysql columns -
iam struggling storing data dynamic form - rows can added/removed during filled.
output form array:
array ( [service] => array ( [0] => 1 [1] => 2 [2] => 3 ) [desc] => array ( [0] => complete service - description [1] => half service - description [2] => break service - description ) [price] => array ( [0] => 1000 [1] => 500 [2] => 800 ) [income_sum] => 2300 [odeslat] => odeslat )
table definition:
column type comment id int(11) auto increment order_id int(11) null servis_id tinyint(4) null price int(11) null desc text null
form definition:
<form action="test.php" method="get" id="form"> <div class='container'> <select name='service[]'> <option value=""></option> <option value="1">complete service</option> <option value="2">half service</option> <option value="3">break service</option> </select> description <input type='text' name='desc[]'> price <input class='income_count' type='text' name='price[]'> <input type="submit"> </form>
i dont have idea how store these multiple columns multiple values. use foreach, failed use multiple variables.
thank much, martin
in test.php count check how many form dataset have got , loop through it:
$total = count($_request['price']); // total $arrservice = $_request['service'];// services array $arrdesc = $_request['desc']; //get desc array $arrprice = $_request['price']; // price array for($i=0;$i<$total;$i++){ $service = $arrservice[$i]; $dsc = $arrdesc[$i]; $price = $arrprice[$i]; //insert data database }
Comments
Post a Comment