Here is my code:
$post_id = 10;
$tags_id = [23, 55, 155, 15];
$stmt = $dbh_conn->prepare("INSERT INTO post_tags (post_id, tag_id) VALUES (?, ?)");
$stmt->execute([$post_id, $tags_id[0]]);
if ( !$stmt->rowCount() ){
throwErrorMessage("Something went wrong while inserting tags");
}
As you can see, my code only inserts one row. I can count the number of count($tags_id) and copy-paste the whole code according to that number. But that approach doesn't seem good to me. Any idea what's the best approach to use an loop on that?