1.記得多選傳陣列 input name的部分 前端要加入中括號 name="faculty_responsibilities[]" 因為是陣列形式
2.前端由於多選 傳過去 是陣列值 所以 必須在後端的部分 先將陣列轉成字串 implode("逗點或空白區隔",變數);
3.後端將字串 傳到mysql
4.前端 藉由 讀出的字串 利用 explode("空白或逗點",變數); 分割字串 將字串再轉為變數
存入$faculty_responsibilities_array[$j]
p.s多選表單需要 multiple="multiple"
<!--前端部分-->
<tr>
<td colspan="4" bgcolor="#e3e3e3"><b>Faculty Responsibilities</b></td>
</tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF"><!--faculty_responsibilities-->
<select multiple="multiple" name="faculty_responsibilities[]">
<?php
$data_avsAnswer = mysql_query("select * from avsAnswer where avsAnswer_Title='Faculty_Responsibilities'", $conn);
$faculty_responsibilities_array= explode(",", $data[17]); //字串轉陣列
$faculty_responsibilities_array_num = count($faculty_responsibilities_array); //陣列數
for($i=0; $i<mysql_num_rows($data_avsAnswer); $i++){ //count($academic_Title) 計算陣列數
$avs=mysql_fetch_row($data_avsAnswer);
$same=0;
for($j=0; $j<$faculty_responsibilities_array_num; $j++){
if(( $faculty_responsibilities_array[$j])==$avs[1]){
$same=1;
}
else{
}
}
if($same==1){ ?>
<option name="faculty_responsibilities" value="<?php echo $avs[1]; ?>"><?php echo $avs[1]."(已選擇)"; ?></option>
<?php
}
else{ ?>
<option name="faculty_responsibilities" value="<?php echo $avs[1]; ?>"><?php echo $avs[1] ?></option>
<?php
}
}
?>
</select>
<!--後端部分-->
<?php
$output=implode(",",$faculty_responsibilities); //陣列轉字串
$faculty_responsibilities = print_r($faculty_responsibilities);
$sql_Professor_Information2 = "UPDATE Professor_Information SET Responsibilitie= '$output' WHERE Id = '$teacherID'";
?>
留言列表