我已经使用 php while 循环显示了一个记录表。 此外,每一行都有一个对应的按钮,即删除和编辑按钮。我为按钮使用了某种 Bootstrap 模式。
表单链接到另一个页面 (具体来说,success.php?id=) 目的是通过其 URL 传递特定行的 ID。但我的问题是传递的 ID 始终是第一行的 ID。
所以这是我的表格的代码。
<?php
$sql = mysql_query("SELECT *
FROM foreignlanguage
INNER JOIN sched
ON sched.sched_id = foreignlanguage.schedID
WHERE sched.type='Group' and foreignlanguage.Subject = 'Italian' and
sched.del='1' and (foreignlanguage.area = 'A1' OR foreignlanguage.area = 'A2' OR foreignlanguage.area = 'A3' OR foreignlanguage.area = 'A4' OR foreignlanguage.area = 'A5')");
$count = mysql_num_rows($sql);
if($count != 0)
{
?>
<table class="table table-striped table-hover table-bordered" id="editable-sample">
<thead>
<tr>
<th><div style="width: 45px" >Level</div></th>
<th><div style="width: 60px" >Days</div></th>
<th><div style="width: 70px" >Time</div></th>
<th><div style="width: 90px" >Teacher</div></th>
<th><div style="width: 10px" >Room</div></th>
<th><div style="width: 10px" >Hours</div></th>
<th><div style="width: 15px" >Price</div></th>
<th><div style="width: 10px" >Options</div></th>
</tr>
</thead>
<tbody>
<?php
while( $get_row = mysql_fetch_assoc($sql))
{
$iClass = $get_row['sched_id'];
$iDay = $get_row['day'];
$iTime = $get_row['time'];
$iTeacher = $get_row['teacher'];
$iRoom = $get_row['room'];
$iHour = $get_row['hour'];
$iPrice = $get_row['price'];
$iLevel = $get_row['area'];
$del = $get_row['del'];
?>
<tr class="">
<td><?php echo $iLevel; ?></td>
<td><?php echo $iDay; ?></td>
<td><?php echo $iTime; ?></td>
<td><?php echo $iTeacher; ?></td>
<td><?php echo $iRoom; ?></td>
<td><?php echo $iHour; ?></td>
<td><?php echo $iPrice; ?></td>
<td>
<!-- Delete MODAL-->
<?php
if(isset($_POST['Delete']))
{
header("Location: success.php");
}
?>
<a href="#delModal" class="btn btn-mini btn-danger" data-toggle="modal" data-target="#delModal"><i class="icon-remove icon-white"></i> Delete</a>
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="delModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Delete Schedule</h4>
</div>
<div class="modal-body">
<!--try-->
Are you sure that you want to delete this schedule?
<!--/try-->
</div>
<div class="modal-footer">
<form method='post' action='success.php?id=<?php echo $iClass; ?>' class="form-horizontal">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-danger" name="Delete" value="Delete">
</form>
</div>
</div>
</div>
</div>
<!-- END DELETE MODAL -->
</td>
</tr>
<?php
}
}
else
{
echo "<h4>There are no schedules available yet</h4>";
}
?>
</tbody>
</table>
这是链接页面。
<?php include('includes/init.php');
$del_this = $_GET['id'];
$delsched = mysql_query(" UPDATE sched SET del = '0' WHERE sched_id = '$del_this' ") or die(mysql_error("ERROR"));
$delsched_list = mysql_query("UPDATE sched_list SET val = '0' WHERE sched_id = '$del_this' ") or die(mysql_error("ERROR"));
echo $del_this;
header("Location: admin-foreign.php");
?>
请帮助我。
最佳答案
有很多方法可以做到这一点。无论如何,您都需要为按钮设置唯一的 ID,这样您就可以将它们设置为 Id="EditButton".$rowid
,对于 delete
关于具有编辑/删除模式的 PHP while 循环仅返回第一行中的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115180/