php - Handling Array field post data -
i searched forum , couldn't find appropriate answer question, array post handling quite new me. have html form array fields,
<input type="text" name="title[]" /> <input type="text" name="desc[]" /> <input type="text" name="cate[]" />
fields generated php , not know how many similar array fields there be. when output post following multidimensional array.
array ( [title] => array ( [0] => title 1 [1] => title 2 [2] => title 3 ) [desc] => array ( [0] => description 1 [1] => description 2 [2] => description 3 ) [cate] => array ( [0] => cat 1 [1] => cat 2 [2] => cat 3 ))
now problem want insert them in db using php foreach. like..:
foreach($_post arraydata) { insert sometable(title,desc,cata)values(title[0],desc[0],cate[0]); }
i tried tricks, merging, joining, explode etc, think there's no exact solution probem below can easy insert them 1 1 thank you:
( [0] => array ( [title] => title 1 [desc] => description 1 [cate] => cat 1 ) [1] => array ( [title] => title 2 [desc] => description 2 [cate] => cat 2 ) [2] => array ( [title] => title 3 [desc] => description 3 [cate] => cat 3 ))
$title = $_post['title']; $desc = $_post['desc']; $cate = $_post['cate']; for($i=1 ; $i < count($title) ; $i++) { insert sometable(title,desc,cata)values($title[$i],$desc[$i],$cate[$i]); }
Comments
Post a Comment