我已经使用表从两个表中获取所有记录,效果很好。我在显示的每一行末尾添加了一个按钮Modal。在此模式中,我想根据每个行 ID 显示数据。
我的代码有一个 while 循环,它显示表中的记录,在该 while 循环中,我又编写了一个 sql 语句,该语句有一个 while 循环,并且应该按照行 ID 运行,但它只为两行获取一个 rowId,并且对所有行显示相同的模式
Please help me out,, how to overcome these mistakes, and where im goin wrong.. Thank u very much for helping me n guiding the correct way
<?php
session_start();
if(!isset($_SESSION)){
header("Location: ../login.php");
exit(); }
include '../header.php';
?>
<!DOCTYPE html>
<html>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Processed Payment
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Tables</a></li>
<li class="active">Data tables</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<!-- /.box -->
<div class="box">
<div class="box-header">
<h3 class="box-title"> Processed Payment
</h3>
</div>
<!-- /.box-header -->
<?php
$email1 = $_SESSION['email'];
$Vendor_id="SELECT Vendor_id FROM vendors where email = '$email1' ";
$result=mysqli_query($conn,$Vendor_id);
$row = mysqli_fetch_row($result);
$sql = "SELECT cp.Customer_payment_id, cp.transaction_id,cp.type,co.Customer_order_id,co.shipping_method,co.tracking_id,co.service_name,co.expected_date_of_Delivery,co.payment_status FROM customer_payment cp, customer_order co where cp.Customer_order_Customer_order_id=co.Customer_order_id and co.Vendors_Vendor_id=$row[0]";
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<form method="post">
<thead>
<tr>
<th>ID</th>
<th>Transaction ID</th>
<th>Payment Type</th>
<th>Status</th>
<th>Order_ID</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($query))
{
$cpid=$row['Customer_payment_id'];
$trd=$row['transaction_id'];
$type=$row['type'];
$pays=$row['payment_status'];
?>
<tr>
<td><?php echo $cpid;?></td>
<td><?php echo $trd;?></td>
<td><?php echo $type;?></td>
<td><?php echo $pays;?></td>
<td><div class="box-body">
<button type="button" name="submit" value=<?php echo $cpid;?> class="btn btn-warning" data-toggle="modal" data-target="#modal-default1">
Order ID</div>
<div class="modal fade" id="modal-default1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Default Modal</h4>
</div>
<div class="modal-body">
<div class="body table-responsive">
<table class="table">
<?php
$modal123 = "SELECT co.Customer_order_id, co.shipping_method,co.tracking_id,co.service_name,co.expected_date_of_Delivery FROM customer_payment cp, customer_order co where cp.Customer_order_Customer_order_id=co.Customer_order_id and cp.Customer_payment_id=$cpid";
$modalqry = mysqli_query($conn, $modal123);
if (!$modalqry) {
die ('SQL Error: ' . mysqli_error($conn));
}
while ($row = mysqli_fetch_array($modalqry))
{
$cid=$row['Customer_order_id'];
$sm=$row['shipping_method'];
$tid=$row['tracking_id'];
$sn=$row['service_name'];
$dod=$row['expected_date_of_Delivery'];
?>
<thead>
<tr>
<th>Order Track_ID</th>
<th><?php echo $cid;?></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Shipping Method</th>
<td><?php echo $sm;?></td>
</tr>
<tr>
<th scope="row">Tracking ID</th>
<td><?php echo $tid;?></td>
</tr>
<tr>
<th scope="row">Service Name</th>
<td><?php echo $sn;?></td>
</tr>
<tr>
<th scope="row">Date of Delivery</th>
<td><?php echo $dod;?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default " data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</td>
<td><a href="../uploads/<?php echo $cpid;?>.pdf"><div class="box-body"><button type="button" class="btn btn-block btn-info ">
<!--<a href="#" class="w3-btn w3-black"></a>-->
<span>Download</span>
</button>
</div></a></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Transaction ID</th>
<th>Payment Type</th>
<th>Status</th>
<th>Order_ID</th>
<th>Download</th>
</tr>
</tfoot>
</form>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php
include '../footer.php';
?>
</html>
它全部显示相同的模态内容,因为所有模态都具有相同的 ID。因此,每次打开模态时,它只显示最后一个模态。要解决此问题,您需要使每个模式的 ID 动态化,或者您可以使用 $cpid 作为模式名称。参考下面的代码:
From:
<div class="box-body">
<button type="button" name="submit" value=<?php echo $cpid;?>
class="btn btn-warning" data-toggle="modal" data-target="#modal-default1"> Order ID
</div>
<div class="modal fade" id="modal-default1">
</div>
将其更改为
<div class="box-body">
<button type="button" name="submit" value=<?php echo $cpid;?>
class="btn btn-warning" data-toggle="modal" data-target="#modal-<?php echo $cpid;?>"> Order ID
</div>
<div class="modal fade" id="modal-<?php echo $cpid;?>">
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)