为了账号安全,请及时绑定邮箱和手机立即绑定

SQL While 语句中的 Bootstrap Modal 不断显示第一条记录内容

SQL While 语句中的 Bootstrap Modal 不断显示第一条记录内容

森栏 2023-01-06 16:01:13
我是新手。我正在转换一个包含发布表单的工作 Bootstrap 模式。使用带有 Id 的按钮打开模式。它总是在打开时显示在 SQL while 语句结果列表中找到的第一条记录的 FORM 内容。我将模态从 id 更改为一个类。我现在用类按钮而不是 id 按钮打开它。但是现在它一直显示第二条记录的表单内容。如果我从模态中取出表格,它可以正常工作并显示正确的内容。accept-btn 打开模式。('.confirm-body') 包含模态内容表单。请感谢一些帮助。<!-- Opens modal is outside the modal--><a class="accept-btn">Accept</a><!-- The Modal --><div class="modal">  <!-- Modal content -->  <div class="modal-content animate confirmarea-size">    <div id="topblue-border1" class="topblue-border1"></div> <!-- topblue border End -->    <!-- Popup buttons Start -->      <div class="confirm-body boxshadow" style="display:none;">      <form class="whatever" action="" method="">         <input type="hidden" class="whatever" name="" value="<?php echo whatever?>">         <input type="hidden" class="whatever" name="" value="<?php echo whatever?>">        <input type="hidden" class="whatever" name="" value="<?php echo whatever?>">        <div class="ajax-response"></div>        <a><div id="css-btn" class="confirm-btn">Accept</div></a>        <a><div id="css-btn" class="cancel-btn">Cancel</div></a>        <a><div id="css-btn" class="nextstage-btn">OK</div></a>      </form>       </div> <!-- Popup Confirm Section END -->   </div> <!-- End of The Modal Content -->      </div> <!-- End of The Modal -->1st Option Button script<script>// Accept button Opens the Modal .$(document).ready(function() {  $('.accept-btn').click(function(event) {    $('.modal').show();    $('.confirm-body').show();  });});</script>2nd Option button  script.  I want to try something like this but I dont know how to code it and close it correctly. each recored has a record Id field.  I want to relate the modal to the record id.
查看完整描述

1 回答

?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

我已经解决了这个问题。一些绕过它的方法很好,比如 AJAX GET Posted here 是有效的。但我知道必须有另一种方法不需要 AJAX GET 命令,而是对模态进行微小的更改,因为我的另一个问题是我在另一个项目上的其他模态包含模态形式的用户输入字段,返回 Js 查询在通过 Ajax 发布表单之前打开 mondal。经过大量的测试和痛苦之后,我找到了解决方案,因为我知道答案在于模态 ID 是静态的。我怎样才能使它动态并匹配 SQL $row id 和 Button ID。答案就在下面。


    1. 在包含行的 Sql 数据库 $row [recordid] 或 ID 的 php 变量中创建。现在,这是确保您获得正确数据所需的变量。

$id  =     "". $row["id"]."";


    1. 在您用来打开模式的按钮中回显记录 id 变量。保持!变量前的哈希#: <button type="button" class="accept-btn" data-toggle="modal" data-target="#<?php echo $id;?>">


    1. 模态 Div - 删除#myModal 并回显 id php 变量。不要放哈希# <div id="<?php echo $id;?>" class="modal">

就这样了。因此,当您单击任何行中的模态按钮时,它将显示正确的内容/形式。


查看完整回答
反对 回复 2023-01-06
  • 1 回答
  • 0 关注
  • 103 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信