【发布时间】:2018-04-11 08:03:22
【问题描述】:
这是我的代码:
$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");
}
如您所见,我的代码只插入一行。我可以计算count($tags_id) 的数量并根据该数字复制粘贴整个代码。但这种方法对我来说似乎并不好。知道在其上使用循环的最佳方法是什么吗?
【问题讨论】: