每行上的模态按钮显示从数据库获取详细信息的模态

2024-02-16

我已经使用表从两个表中获取所有记录,效果很好。我在显示的每一行末尾添加了一个按钮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 Below is the table, on clicking modal i want to display modal as per each row ID

<?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">&times;</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(使用前将#替换为@)

每行上的模态按钮显示从数据库获取详细信息的模态 的相关文章

  • 之后的脚本会阻止 DOM 加载

    考虑以下代码 div class box div 令我惊讶的是 DOM 延迟了十秒的加载 10秒后出
  • Internet Explorer 不渲染从 JQuery ajax 帖子返回的 html

    我有一个带有输入框的页面 其 onkeyup 根据输入的内容 搜索字段 触发 JQuery ajax 帖子 ajax 调用回发的 html 应该填充页面上的另一个 div 这是 jquery ajax 帖子 var o me results
  • 数组到命名变量

    我该如何服用 userarray 这是一个数组 我知道它包含 3 个值 并将它们放入 3 个单独的变量中 而不是循环遍历 那里隔着 commas 所以爆炸会在某个地方发生 Say userfield1 userfield2 userfiel
  • Bootstrap .row margin-left: -15px - 为什么它会缩进(来自文档)

    我在 Bootstrap 文档中看到了这一行 http getbootstrap com css grid intro http getbootstrap com css grid intro It says 列通过填充创建装订线 列内容之
  • CodeIgniter 控制器构造函数

    我对 codeigniter 很陌生 我想知道控制器中构造函数的含义是什么 我在 codeigniter 教程中看到以下代码 class upload extends CI Controller function construct par
  • PHP $_SERVER['REMOTE_HOST'] 返回 ::1 [重复]

    这个问题在这里已经有答案了 可能的重复 应该 ip SERVER REMOTE ADDR 在 mamp 本地主机上返回 1 https stackoverflow com questions 3699454 should ip server
  • 如何使div垂直滚动[重复]

    这个问题在这里已经有答案了 我用图片元素列表做了一个水平滚动 但是当我垂直滚动它时我失败了 我的水平滚动条代码是 div class pic container div class pic row div style width 100 a
  • 带单引号的 XPATH 查询[重复]

    这个问题在这里已经有答案了 有人知道如何解决这个问题吗 单引号让我陷入困境 nodes xml gt xpath item contains catalog Billy s Blogs title 我尝试以各种方式逃避它 但都抛出错误 no
  • 如何从 URL 获取当前的 Web 目录?

    如果我有一个网址http www example com sites dir index html http www example com sites dir index html 我想提取 sites 这个词 我知道我必须使用正则表达式
  • MySQL LAST_INSERT_ID() 和 FOUND_ROWS()

    当 PHP 脚本每秒有数百个查询时会发生什么 它会影响这些函数吗 是否保证它们会返回当前脚本中最后一个插入语句中最后插入的 id 它会返回当前脚本中最后一次选择的行数吗 如果同时从另一个脚本进行新的插入或选择 在 FOUND ROWS 的情
  • 如何访问带有美元符号的 PHP 对象属性?

    我有一个 PHP 对象 其属性中有一个美元 符号 如何访问该属性的内容 例子 echo object gt variable Ok echo object gt variable WithDollar Syntax error With 变
  • HTML CSS 循环协助

    希望你能帮忙 我想知道您是否可以在循环中创建以下类型 你知道这是否可能吗 body background 000 DEMO SPECIFIC STYLES typewriter h1 color fff font family Bebas
  • 我可以在 php 中的 SESSION 数组上使用 array_push 吗?

    我有一个想要在多个页面上使用的数组 因此我将其设为 SESSION 数组 我想添加一系列名称 然后在另一个页面上 我希望能够使用 foreach 循环来回显该数组中的所有名称 这是会议 SESSION names 我想使用 array pu
  • SVG 过滤器在 Firefox 中不显示,在 Chrome 中工作正常

    我想要深色背景上的一段深色文本外面有白色的光芒 虽然默认阴影滤镜 https developer mozilla org en US docs Web CSS filter drop shadow 2在 CSS 中 比如filter dro
  • 为什么我在 WinForms 列表框中得到“System.Data.DataRowView”而不是实际值?

    每当我运行代码并尝试查看highscore我在列表框中得到的只是System Data DataRowView 谁能明白为什么吗 Code MySqlConnection myConn new MySqlConnection connStr
  • 将 ngModel 绑定到自定义指令

    所以我已经在这个问题上工作了一个星期了 但我似乎无法理解整个指令的事情 我读了很多帖子 揭秘指令 http www toptal com angular js angular js demystifying directives 指令 ht
  • snappy wkhtmltopdf 包装器将生成的 html 文件发送到浏览器

    我像鼹鼠一样用谷歌搜索 但找不到正确的方法 我正在使用 WKHTMLTOPDF Wrapper Snappy 创建 PDF 如何将使用generateFromHtml方法生成的pdf直接发送到浏览器 这就是我想做的 header Conte
  • 单击行内的按钮时防止触发表行 onclick 事件

    我有一个带有 ONCLICK 事件的表行 切换下面的附加数据 在其中一个行单元格内有一个按钮 单击时执行 AJAX 操作 当我单击按钮时 行的 onclick 事件也会触发 并且会发生附加数据在 AJAX 调用完成之前出现 这对我来说是一个
  • MySQL 查询中的窗口函数

    有没有办法在 SELECT 查询本身中动态地使用 MySQL 查询中的窗口函数 我知道在 PostgreSQL 中这是可能的 例如 下面是 PostgreSQL 中的等效查询 SELECT c server ip c client ip s
  • MyBatis 枚举的使用

    我知道以前有人问过这个问题 但我无法根据迄今为止找到的信息实施解决方案 所以也许有人可以向我解释一下 我有一个表 状态 它有两列 id 和 name id是PK 我不想使用 POJO Status 而是使用枚举 我创建了这样一个枚举 如下所

随机推荐