這是我的var_dump($ img);將數組插入到mysql的多個行中
array(2) {
[0]=>
string(5) "1.jpg"
[1]=>
string(5) "2.PNG"
}
在開始我想我可以使用序列化,但它只能插入一行。下面
foreach($img as $k){
//Insert into database here. This will add all the records which are in array.
}
$ķ
if(!empty($img_src)){
foreach ($img_src as $key => $value) {
$targeted_post_id = $db->insert_id;
$stmt = $db->prepare("INSERT INTO photo_upload(`post_id`,`img_src`) VALUES (?,?)");
$stmt->bind_param('is', $targeted_post_id,$value);
$stmt->execute();
}
}
使用foreach($ img); –
並在foreach中寫入插入查詢 – SajithNair