gpt4 book ai didi

php - 如何在模态中传递表的ID值

转载 作者:行者123 更新时间:2023-11-29 19:11:21 25 4
gpt4 key购买 nike

我想以模态形式传递学生的id值。当我单击 1stgrade 按钮时,这是我的表格代码:

<tbody>
<?php
require_once '../dbconfig.php';

$stmt = $db_con->prepare("SELECT * FROM userinfo WHERE role='student' AND gradelvl='7' AND sectionname='$_POST[table7]' ORDER BY lrnno ASC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['fname']; ?></td>

这是我的模态形式:

<td>
<div align="center">
<form action="studentprofilegradeaction.php" method="POST" class="form-horizontal">
<input type='text' name='id' value='<?php echo $row['id']; ?>' />
<!-- Button HTML (to Trigger Modal) -->
<a href="#1stgrade7" class="btn btn-info" data-toggle="modal"><i class="fa fa-building"></i>1st</a>
<!-- Modal HTML -->

<div id="1stgrade7" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<input type='text' value='<?php echo $row['id'] ?>' />

<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title">Please Fill Correctly</h2>
</div>
<div class="modal-header">
<h4 class="modal-title">1st Grading Result </h4>
</div>

<div class="modal-body">
<div align="left">
<b>Filipino:</b>
<input type="text" class="form-control" name="c71stgfilipino" >
</div>

我想将 ID 号传递给模态一年级。

最佳答案

替换您的 anchor 标记:

<a href="#1stgrade7"  class="btn btn-info" data-toggle="modal"><i class="fa fa-building"></i>1st</a>

=>

<a id="openModal" data-id="<?php echo $row['id']; ?>" class="btn btn-info"><i class="fa fa-building"></i>1st</a>

从 while 循环中删除其他不必要的代码,将模态代码保留在循环之外,并将 id 赋予模态内的 id 输入:

<input id="userId" type='text' value='<?php echo $row['id'] ?>' />

然后你需要jquery来读取点击行的od并将其设置为模态,然后写下:

<script>
$(document).ready(function() {

$("#openModal").click(function() {

//remove previous value
$("#userId").val("");

//this ll set id to your modal input
$("#userId").val($(this).attr("data-id"));

//open the modal
$("#1stgrade7").modal("show");

});
});
</script>

关于php - 如何在模态中传递表的ID值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43052369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com