如何通过单击超链接 table 单元格使用 bootstrap 4 打开模式并使用单击的 ID 从 SQL 数据库填充模型中的数据
How do I open modal using bootstrap 4 by clicking a hyperlinked table cell and populate data in the model from SQL database using the clicked ID
我有一个页面在 table 中显示来自 SQL 的数据,在那个 table 上有一个单元格是超链接的,我想要一个模式(使用 bootstrap)使用 ID(超链接值)打开和获取数据,并从 SQL 以模态填充正文中的数据。我尝试了不同的方法,但 none 效果很好。模式打开但它并不突出,就好像它在背景中打开一样。请帮我解决这个问题。
HEAD 中使用的链接:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script>
PHP代码
<?php
while ($ticketdata = mysqli_fetch_array($ticketresults))
{
// Print out the contents of the entry
echo '<tbody>';
echo '<th scope="row"><a href="#" data-toggle="modal" data-target="#ticketModal'.$ticketdata['ticketnumber'].'">';
echo $ticketdata['ticketnumber'];
echo '</a>';
echo '</th>';
echo '<td>' . $ticketdata['policynumber'] . '</td>';
echo '<td>' . $ticketdata['registration_number'] . '</td>';
echo '<td>' . $ticketdata['insuredname'] . '</td>';
echo '<td>' . $ticketdata['contactnumber'] . '</td>';
echo '<td>' . $ticketdata['casestatus'] . '</td>';
echo '<td>';
echo '<form method="post">';
echo '<input type="hidden" name="ticketnumber" value="'. $ticketdata['ticketnumber']. '">';
echo '<input type="submit" class="btn btn-danger btn-sm" name="deletedata" value="Delete">';
echo '</form>';
echo '</td>';
echo '</tbody>';
}
?>
如何将 ID 传递给模态以及我应该在哪里初始化传递 ID 的模态(超链接)以使用带有 PHP 脚本的 ID 使用数据填充模态?
<table>
<?php
while($ticketdata = mysqli_fetch_array($ticketresults)){
<tr>
<td><a href="#" id="<?php echo $ticketdata['ticketnumber']; ?>" class="view_data" /><?php echo $ticketdata['ticketnumber']; ?></a></td>
<td><?php echo $ticketdata['name']; ?></td>
<td><?php echo $ticketdata['policynumber']; ?></td>
<td><?php echo $ticketdata['registration_number']; ?></td>
<td><?php echo $ticketdata['insuredname']; ?></td>
<td><?php echo $ticketdata['contactnumber']; ?></td>
<td><?php echo $ticketdata['casestatus']; ?></td>
<td>DELETE</td>
</tr>
<?php } ?>
</table>
</body>
</html>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Policy Details</h4>
</div>
<div class="modal-body" id="detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Ajax代码:-
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var ticket_id = $(this).attr("id");
$.ajax({
url:"select.php",
method:"post",
data:{ticket_id:ticket_id},
success:function(data){
$('#detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
select.php:-
<?php
if(isset($_POST["ticket_id"]))
{
$output = '';
$connect = mysqli_connect("localhost", "root", "", "testing");
$query = "SELECT * FROM table_name WHERE id = '".$_POST["ticket_id"]."'";
$result = mysqli_query($connect, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td width="30%"><label>S. No</label></td>
<td width="70%">'.$row["ticketnumber"].'</td>
</tr>
<tr>
<td width="30%"><label>Ticket Name</label></td>
<td width="70%">'.$row["name"].' Year</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
我有一个页面在 table 中显示来自 SQL 的数据,在那个 table 上有一个单元格是超链接的,我想要一个模式(使用 bootstrap)使用 ID(超链接值)打开和获取数据,并从 SQL 以模态填充正文中的数据。我尝试了不同的方法,但 none 效果很好。模式打开但它并不突出,就好像它在背景中打开一样。请帮我解决这个问题。
HEAD 中使用的链接:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script>
PHP代码
<?php
while ($ticketdata = mysqli_fetch_array($ticketresults))
{
// Print out the contents of the entry
echo '<tbody>';
echo '<th scope="row"><a href="#" data-toggle="modal" data-target="#ticketModal'.$ticketdata['ticketnumber'].'">';
echo $ticketdata['ticketnumber'];
echo '</a>';
echo '</th>';
echo '<td>' . $ticketdata['policynumber'] . '</td>';
echo '<td>' . $ticketdata['registration_number'] . '</td>';
echo '<td>' . $ticketdata['insuredname'] . '</td>';
echo '<td>' . $ticketdata['contactnumber'] . '</td>';
echo '<td>' . $ticketdata['casestatus'] . '</td>';
echo '<td>';
echo '<form method="post">';
echo '<input type="hidden" name="ticketnumber" value="'. $ticketdata['ticketnumber']. '">';
echo '<input type="submit" class="btn btn-danger btn-sm" name="deletedata" value="Delete">';
echo '</form>';
echo '</td>';
echo '</tbody>';
}
?>
如何将 ID 传递给模态以及我应该在哪里初始化传递 ID 的模态(超链接)以使用带有 PHP 脚本的 ID 使用数据填充模态?
<table>
<?php
while($ticketdata = mysqli_fetch_array($ticketresults)){
<tr>
<td><a href="#" id="<?php echo $ticketdata['ticketnumber']; ?>" class="view_data" /><?php echo $ticketdata['ticketnumber']; ?></a></td>
<td><?php echo $ticketdata['name']; ?></td>
<td><?php echo $ticketdata['policynumber']; ?></td>
<td><?php echo $ticketdata['registration_number']; ?></td>
<td><?php echo $ticketdata['insuredname']; ?></td>
<td><?php echo $ticketdata['contactnumber']; ?></td>
<td><?php echo $ticketdata['casestatus']; ?></td>
<td>DELETE</td>
</tr>
<?php } ?>
</table>
</body>
</html>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Policy Details</h4>
</div>
<div class="modal-body" id="detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Ajax代码:-
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var ticket_id = $(this).attr("id");
$.ajax({
url:"select.php",
method:"post",
data:{ticket_id:ticket_id},
success:function(data){
$('#detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
select.php:-
<?php
if(isset($_POST["ticket_id"]))
{
$output = '';
$connect = mysqli_connect("localhost", "root", "", "testing");
$query = "SELECT * FROM table_name WHERE id = '".$_POST["ticket_id"]."'";
$result = mysqli_query($connect, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td width="30%"><label>S. No</label></td>
<td width="70%">'.$row["ticketnumber"].'</td>
</tr>
<tr>
<td width="30%"><label>Ticket Name</label></td>
<td width="70%">'.$row["name"].' Year</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>