将值传递给用于PHP PDO查询的Bootstrap模式

时间:2015-12-05 23:19:18

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

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

这是我的删除模式

<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查询并执行它,同时能够在表上显示数据。

1 个答案:

答案 0 :(得分:0)

JQuery在客户端执行,而SQL查询在服务器端执行。 所以,你需要使用AJAX。这将是一个非常长的答案,请看一下这个Specifically for geojson