在以下代碼中,問題是隱藏輸入字段(名爲「res_id」)的值將固定到表的第一行。知道我在這裏運行一個foreach循環來生成res_id字段的值,我期望每次foreach循環開始時都有唯一的值。請注意表格數據字段或<td>
呈現正確的值。換句話說,如果我嘗試在動作php頁面中回顯res_id的POST值,它將保持相同的值!希望我清楚。非常感激你的幫助。在表格內張貼PHP數據
<div>
<form id="form_st_feedback" class="form-horizontal" action="st_fdbk.php" method="post" onsubmit="return confirm('Are you sure?');">
<table class="table table-bordered">
<thead>
<th style="width:10%; padding:0px; margin:0px;">Res. ID</th>
<th style="width:10%; padding:0px; margin:0px;">Class Date</th>
<th style="width:10%; padding:0px; margin:0px;">Tutor</th>
<th style="width:15%; padding:0px; margin:0px;">How was your class?</th>
<th style="width:55%; padding:0px; margin:0px;">Your comment</th>
</thead>
<tbody>
<?php
$tt=null;
$rr = null;
$mypdo2 = Database::connect();
$mypdo2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$mysql3 = "SELECT * FROM tbl_reservation WHERE res_st_id = $user_id AND res_del=FALSE AND teacher_cant_mkit=FALSE ORDER BY res_date";
$myq3 = $mypdo->prepare($mysql3);
$myq3->execute(array());
$mydata3 = $myq3->fetch(PDO::FETCH_ASSOC);
foreach ($mypdo2->query($mysql3) as $row) {
$res_id=$row['res_id'];
$mysql4 = "SELECT * FROM tbl_st_page_feedbk WHERE fb_res_id = ? LIMIT 1"; // linking to feedback table
$myq4 = $mypdo2->prepare($mysql4);
$myq4->execute(array($res_id));
$mydata4 = $myq4->fetch(PDO::FETCH_ASSOC);
$tt=$row['res_date'].$row['res_time'];
$str_tt0= date('m/d/Y H:i', strtotime($tt));
$str_tt=strtotime($str_tt0);
if ( ($str_tt - $timenow<=-600)) { //10 mins after class started
echo '<tr>';
echo '<td>'. $res_id .'</td>';
echo "<input type='hidden' name='res_id' value='$res_id'>";
echo '<td>'. $row['res_date'].'<br />'.$row['res_time'] .'</td>';
if ($row['res_tut_id']==10) {echo '<td>' . 'Kim' . '</td>';}
if ($row['res_tut_id']==16) {echo '<td>' . 'Morly' . '</td>';}
if ($row['res_tut_id']==22) {echo '<td>' . 'Arlene' . '</td>';}
if ($row['st_rep_feedbk']=='NO') {
echo '<td>' .'<select name="selected_quality"style="color:blue;">
<option value="Excellent">Excellent (5/5)</option>
<option value="Good">Good (4/5)</option>
<option value="Fair">Fair (3/5)</option>
<option value="Poor">Poor (2/5)</option>
<option value="Very Poor">Very Poor (1/5)</option>
</select>'
.'</td>';
echo '<td>'
.'<textarea id="comment_txt" name="comment_txt" style="color:#00f; display:inline; flloat:left;" rows="2" maxlength="80" value=""></textarea>'
.'<br />'
.'<button id="submit" type="submit" class="btn btn-success" style="display:block; margin:2px auto; padding:2px 5px;">Submit</button>'
.'</td>';
}
else { echo '<td>'.$mydata4['fb_quality'].'</td>';
echo '<td>'.$mydata4['fb_comment'].'</td>';
}
echo '</tr>';
} // end of if
} //end of foreach
Database::disconnect();
?>
</tbody>
</table>
</form>
</div>
問題是你有多個同名的元素!讓它成爲'name ='res_id []''! – Jeff
更多信息:http://stackoverflow.com/questions/4688880/html-element-array-name-something-or-name-something – Jeff