SQL While语句中的Bootstrap Modal始终显示第一个记录内容

如何解决SQL While语句中的Bootstrap Modal始终显示第一个记录内容

我是新手。我正在转换一个包含发布表格的工作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.

<script>
//Accept Bid Button Opens the Modal and displays the Confirm-Body Div.
$(document).ready(function(){
$('.acceptbid-btn').click(function(event){ 
var myModal = "myModal" + $('.recordid').val();
$  $(this).closest('recordid').find('modal').modal({
            keyboard: true
        },'show');
        return false;
$('.confirm-body').show();


});
});
});

</script>


UPDATE:
I have done this using php.  The button and the modal ids 
now matches the Row record id. And will always be unique. 
I am going some where with this idea,not sure yet I am 
yet to test what happens.

<?php  $buttonid = $recordid;?>
 <a  id="<?php echo $buttonid;?>" class="acceptbid-btn"></a>


<!-- The Modal -->
<div id="<?php echo $buttonid;?>" class="modal">

解决方法

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

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

$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">

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

,

我研究了类似的模式。让我给你看一个例子..

data-id按钮

 <button type="button" class="btn btn-info btn-xs btn_width editPrescription" data-toggle="modal" data-id="<?php echo $prescription->id; ?>"><i class="fa fa-edit"></i>
                                                        <?php echo lang('edit'); ?>
                                                    </button>

这是一个模式,其ID为myModal2

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title"><i class="fa fa-edit"></i> <?php echo lang('edit_medical_history'); ?></h4>
        </div>
        <div class="modal-body">
            <form role="form" action="patient/addMedicalHistory" id="medical_historyEditForm" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="exampleInputEmail1">
                        <?php echo lang('date'); ?>
                    </label>
                    <input type="text" class="form-control form-control-inline input-medium default-date-picker" name="date" id="exampleInputEmail1" value='' placeholder=""> </div>
                <div class="form-group col-md-12">
                    <label class="control-label col-md-3">Initiated By: </label>
                    <div class="col-md-9">
                        <input type="text" class="form-control form-control-inline" name="initiated_by" id="" value='' readonly=""> </div>
                    <br>
                </div>
                <div class="form-group col-md-12">
                    <label class="control-label col-md-3">
                        <?php echo lang('description'); ?>
                    </label>
                    <div class="col-md-9">
                        <textarea class="ckeditor form-control editor" id="editor" name="description" value="" rows="10"></textarea>
                    </div>
                </div>
                <input type="hidden" name="patient_id" value='<?php echo $patient->id; ?>'>
                <input type="hidden" name="id" value=''>
                <section class="">
                    <button type="submit" name="submit" class="btn btn-info submit_button">Submit</button>
                </section>
            </form>
        </div>
    </div>
    <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->

这是Ajax,使用数据触发模态,但问题是您必须创建一个页面,该页面通过php JSON将数据发送回ajax

<script type="text/javascript">
$(document).ready(function() {
    $(".editbutton").click(function(e) {
        e.preventDefault(e);
        // Get the record's ID via attribute  
        var iid = $(this).attr('data-id');
        $('#myModal2').modal('show');
        $.ajax({
            url: 'patient/editMedicalHistoryByJason?id=' + iid,method: 'GET',data: '',dataType: 'json',}).success(function(response) {
            // Populate the form fields with the data returned from server
            $('#medical_historyEditForm').find('[name="id"]').val(response.medical_history.id).end()
            $('#medical_historyEditForm').find('[name="date"]').val(response.medical_history.date).end()
            $('#medical_historyEditForm').find('[name="initiated_by"]').val(response.medical_history.initiated_by).end()
            CKEDITOR.instances['editor'].setData(response.medical_history.description)
        });
    });
});

我希望这可以使您了解其工作原理。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-