【问题标题】:Passing value to Bootstrap Modal for PHP PDO Query将值传递给引导模式以进行 PHP PDO 查询
【发布时间】:2015-12-05 23:19:17
【问题描述】:

我正在显示一个包含两个选项(删除或更新)的值表。当我选择删除时,我想显示要删除的行。最后一点使用 Bootstrap 模态。

这是我的删除模式

<div class="modal bounceIn animated" id="Delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Delete a Campaign</h4>
      </div>
      <div class="modal-body edit-content">

        <p>Please find the campaign ID to be deleted below</p>
        <input type="text" name="bookId" id="bookId" value="" />


        <table class='table table-bordered'>
          <tr>
            <th>#</th>
            <th>Description</th>
            <th>Creation Date</th>
            <th>Credit</th>
            <th>ROI</th>
            <th>Active</th>
          </tr>
          <?php

             $id = $row['data-campaignid'];// This is where I am having the problem
             $stmt = $user_home->runQuery("SELECT * FROM campaigns WHERE id_campaigns=:id");
               $stmt->execute(array(":id"=>$id));
             while($row=$stmt->fetch(PDO::FETCH_BOTH))
             {
                 ?>
            <tr>
              <th>
                <?php print($row['id_campaigns']); ?>
              </th>
              <th>
                <?php print($row['descripcion']); ?>
              </th>
              <th>
                <?php print($row['fec_creacion']); ?>
              </th>
              <th>
                <?php print($row['saldo']); ?>
              </th>
              <th>
                <?php print($row['ROI']); ?>
              </th>
              <th>
                <?php print($row['active']); ?>
              </th>
            </tr>
            <?php
             }
             ?>
        </table>

      </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>
<!-- end -->

如您所见,我正在使用以下 JQuery 脚本将值“bookid”传递给模式

$(document).on("click", ".open-DeleteDialog", function () {
     var myCampaignId = $(this).data('campaignid');
     $(".modal-body #bookId").val( myCampaignId );

});

我遇到的困难是如何使用输入的值 (bookID) 将其传递给 PHP PDO 查询并执行它,同时能够在表上显示该数据。

【问题讨论】:

标签: php jquery twitter-bootstrap pdo bootstrap-modal


【解决方案1】:

JQuery 在客户端执行,而 SQL 查询在服务器端。 所以,你需要使用 AJAX。这将是一个很长的答案,请看看这个CRUD+AJAX tutorial

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多