database - how to insert array values in a single column in mysql with php? -
m dealing checkbox selection
<input type="checkbox" name="chk_group[]" value="1"> <input type="checkbox" name="chk_group[]" value="2"> <input type="checkbox" name="chk_group[]" value="3"> <input type="checkbox" name="chk_group[]" value="4">
here im getting values of checked checkboxes in array:
$ids = array(); foreach($_post['chk_group'] $val) { $ids[] = (int) $val; } echo $ids = implode(',', $ids);
if check 2nd , 3rd checkbox [2,3] value in array $id
. problem want store these values separately in db table column
table is:
product_attribute
- id
- a_id
i want insert values array in column a_id
id ------ a_id
1 ------- 2
2 ------- 3
how can use insert query store data in mysql table??
where have
implode(',', $ids)
replace sql. example:
$db->query("insert product_attribute (a_id) values (" . implode('),(', $ids) . ")");
i leave casting loop sanitizes data.
Comments
Post a Comment