开发者

insert multiple rows into mysql table - one column from constant value, other from an array

开发者_如何学编程

How do insert multiple rows into a mysql table, with one column remaining constant, and the other as an array.

//inserted profession into professions table, return id
$new_profession_id = mysql_insert_id(); 

$qualification_array = array();

foreach ($_POST['qualification'] as $qual){
    array_push($qualification_array, $qual);
}

$query = "???

now how would I insert this into the profession_has_qualification table? its got me stumped...


You can do like this:

$new_profession_id = mysql_insert_id(); 

foreach ($_POST['qualification'] as $qual){
   mysql_query("insert into TableName set pid = $new_profession_id, qualification = '" . mysql_real_escape_string($qual) . "'");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜