具有多个类别选择和注册的PDO

时间:2014-10-29 10:43:25

标签: php mysql pdo

祝你有个愉快的一天 我使用的是PDO, 我想制作一个多类别的选择内容。 得分如下

$categories= implode(",", $_POST["category"]); // 3,6,8

但是我无法保存到数据库中,因为它遵循

id | content_id | category_id

1  | 1          | 3    
2  | 1          | 6
3  | 1          | 8

如何保存到数据库, 非常感谢你

1 个答案:

答案 0 :(得分:0)

真是奇迹吗?它运作得更快

 $sql="INSERT INTO `$table` (`content_id`,`category_id`) VALUES(:a,:b)";
            foreach($data as $item) {
            $sorgum = $db->prepare($sql);
            $sorgum->bindValue(':a', $content_id , PDO::PARAM_INT);
            $sorgum->bindValue(':b', $item , PDO::PARAM_INT);
            $sonuc=$sorgum->execute();  
            }