我有一个从mysql数据库动态填充的表。用户应该选择一个staff number
,它会自动进入数据库并获取他的员工编号。我有10行。它适用于第一行,但不适用于其他其他行。动态填充数据库中的每一行使用php-Ajax
请看看我错过它的代码和建议。
由于
<tr>
<th nowrap="nowrap">S/N</th>
<th nowrap="nowrap">VNO</th>
<th nowrap="nowrap">Name</th>
<th nowrap="nowrap">Staff No</th>
</tr>
<tr>
<?php
$c=0;
$st =mysqli_query($connection,"SELECT * FROM tab_flt WHERE mainloc='".$_SESSION['location']."' AND status='Active'");
while($r = mysqli_fetch_array($st)){ $c++?>
<td><?php echo $c;?></td>
<td><input type="text" name="flt[]" value="<?php echo $r['fltno'];?>" class="form-control" readonly="readonly" /></td>
<td><select name="opname[]" class="form-control" id="subloc">
<option>Select...</option>
<?php
$fs = getOperators($_SESSION['location']);
while($f = mysqli_fetch_array($fs)){?>
<option value="<?php echo $f['name'];?>"><?php echo $f['name'];?></option>
<?php };?>
</select></td>
<td id="staffno"></td>
</tr>
Ajax的侧:
<script type="text/javascript">
$(document).ready(function() {
$("#subloc").change(function(){
var sname = $("#subloc option:selected").val();
$.ajax({
type:"POST",
url:"process-opno.php",
data:{opname:sname}
}).done(function(data3){
$("#staffno").html(data3);
});
});
});
</script>
当成功地选入staffno ID subloc ID上面取第一行。 但它没有为剩余的线路做。我能做什么,它会识别第二行,第三行等,并将相应的员工编号提取到staffno id中。
谢谢。
为什么你使用fetch_array两次? – Maxzeroedge