继承我的代码:带有服务器端的HTML从数据库中获取数据。如何使用复选框选项从数据表中获取ID?
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<h4>
<th></th> <!-- For checkbox column-->
<th>ID Number</th>
<th>Lastname</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Gender</th>
<th>Course</th>
<th>Department</th>
<th>Address</th>
<th>Contact</th>
<th>Birthdate</th>
<th>View</th>
<th>Events</th>
</h4>
</tr>
</thead>
<tbody>
<?php
include 'pgconnect.php';
$mydata = mysqli_query($conn,"SELECT * FROM student") or die(mysql_error());
while($record = mysqli_fetch_assoc($mydata))
{
$id=$record['id'];
?>
<tr>
<td><input type="checkbox"></td>
<td class="id"><?php echo $record['id'] ?></td>
<td class="lname"><?php echo $record['last_name'] ?></td>
<td class="fname"><?php echo $record['first_name'] ?></td>
<td class="mname"><?php echo $record['mid_name'] ?></td>
<td class="sex"><?php echo $record['gender'] ?></td>
<td class="course"><?php echo $record['course'] ?></td>
<td class="dept"><?php echo $record['department'] ?></td>
<td class="add"><?php echo $record['home_address'] ?></td>
<td class="contact"><?php echo $record['contact'] ?></td>
<td class="bdate"><?php echo $record['birthdate'] ?></td>
<td><a href="records1.php?id="> View Records </a> </td>
<td> <a title='Click here to update record.'href='#edit' data-toggle='modal'><i class="fa fa-pencil fa-fw"></i></a>
<a title='Click here to add record.' href='#'><i class="fa fa-plus fa-fw"></i></a>
<a title='Click here to delete record.' href='delete.php?del=<?php echo $record['id'] ?>'><i class="fa fa-trash-o fa-fw"></i></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
这是我的剧本:
$(document).ready(function(){
$('#dataTables-example').dataTable();
});
我试图获取ID,但它仍然没有用。希望你能帮帮我。
答案 0 :(得分:0)
在您的工作中,您将获得表格中的ID。如果你使用jquery,你应该从复选框中获取它,如;
<script>
$(document).ready(function(){
document.getElementByID("ckmyid").innerHTML;
});
</script>
注意:在复选框中添加选择器ID,首先说“ckmyid”,所以代码将是这样的:
<input id="ckmyid" type="checkbox" value="<?php echo $record['id'] ?>">
根据您的结构,如果您想在其中放置ID,可以直接从查看记录链接中的链接抓取它,如;
<td><a href="records1.php?id=<?php echo $record['id'] ?>"> View Records </a> </td>