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) . "'");
}
精彩评论