当我在一个页面中放置两个sql查询时,我在显示表时遇到问题。当我只输入一个查询时,我没有这个问题。
我想显示学生名单 student table
讲师可以将学生添加到自己的护理中,具有添加功能。我已经做了编码,但我遇到了问题。
这是我的密码
<table id=" table" class="table table-bordered">
<thead>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Email</th>
<th>Contact Number</th>
<th>Programme Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "SELECT * FROM `student`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
?>
<tr class="del_student<?php echo $fetch['student_id']?>">
<td><?php echo $fetch['student_id']?></td>
<td><?php echo $fetch['student_name']?></td>
<td><?php echo $fetch['student_email']?></td>
<td><?php echo $fetch['contact_number']?></td>
<td><?php echo $fetch['programme_type']?></td>
<td><?php echo $fetch['status_type']?></td>
<td><center><button class="btn btn-warning" data-toggle="modal" data-target="#edit_modal<?php echo $fetch['student_id']?>"><span class="glyphicon glyphicon-edit"></span> Edit</button> </center>
</td>
</tr>
<div class="modal fade" id="edit_modal<?php echo $fetch['student_id']?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form method="POST" action="update_student.php">
<div class="modal-header">
<h4 class="modal-title">Add Supervisee</h4>
</div>
<div class="modal-body">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<label>Student ID</label>
<input type="hidden" name="id" value="<?php echo $fetch['id']?>" class="form-control"/>
<input type="number" name="student_id" value="<?php echo $fetch['student_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Name</label>
<input type="text" name="student_name" value="<?php echo $fetch['student_name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Email</label>
<input type="email" name="student_email" value="<?php echo $fetch['student_email']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Contact Number </label>
<input type="text" name="contact_number" value="<?php echo $fetch['contact_number']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Programme Type</label>
<input type="text" name="programme_type" value="<?php echo $fetch['programme_type']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" name="status_type" value="<?php echo $fetch['status_type']?>" class="form-control" required="required"/>
</div>
<label>Supervisor Information</label>
<div class="form-group">
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
<label>Supervisor ID</label>
<input type="text" name="supervisor_id" value="<?php echo $fetch['work_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Name</label>
<input type="text" name="supervisor_name" value="<?php echo $fetch['name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Role </label>
<select name="supervisor_role" class="form-control" required="required">
<option value="Chose supervisor role"></option>
<option value="Supervisor">Supervisor</option>
<option value="Co - Supervisor">Co-Supervisor</option>
</select>
</div>
</div>
</div>
<div style="clear:both;"></div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
<button name="update" class="btn btn-warning" ><span class="glyphicon glyphicon-save"></span> Update</button>
</div>
</form>
</div>
</div>
<?php
}
?>
</tbody>
</table>
</div>
</div>
我注意到当我输入这个查询时,这个表没有显示学生的完整列表
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
我想要实现的是我想要在数据库中显示所有注册的学生,讲师可以添加学生,学生信息连同讲师id和姓名一起将保存到数据库中。如何解决这个问题?
1条答案
按热度按时间xam8gpfp1#
您正在使用
$fetch
获取两个查询的结果。下面是代码中发生的事情。
你的
$fetch
从学生表中获取结果。显示表内容,直到它到达第二个查询。
当你的第二个查询被执行时,
$fetch
值被更改。因此,学生的表格只显示一行。更改
$fetch
在第二个问题中,比如$fetch2