使用SQL和amp;将数据从页面传递到引导模式的PHP [英] Passing data from page to bootstrap modal using SQL & PHP

查看:62
本文介绍了使用SQL和amp;将数据从页面传递到引导模式的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,按照标题,我试图在引导模式下使用sql传递来自数据库的显示多个数据.该ID将从链接中传递下来,如何完成?一直在寻找多种方法,但我仍然无法显示所选数据;

So as per title, im trying to pass show multiple data from database using sql on the bootstrap modal. The ID will be pass down from the link, how is it done? been finding multiple way but I still can't show the selected data;

所以这是模态的触发器:

So here is the trigger for the modal:

<?php  while($row = mysqli_fetch_array($adm_query)){
    $id = $row['admin_id'];  ?>
<tr>
	<td style="text-align:center"><?php echo $row['adm_name']; ?></td>
	<td width="150" style="text-align:center"><?php echo $row['staff_no']; ?></td>
	<td width="120" style="text-align:center"><?php echo $row['department']; ?></td>
	<td width="138" style="text-align:center;">
												
      <a data-toggle="modal" data-target="#myModal" data-id="<?php echo $row['admin_id']?>" class="btn btn-outline btn-info"><i class="fa fa-search-plus"></i></a>
    </td>
<?php 	}?>

这是模态内容:

<!-- Modal -->
<div style="margin-top:5%;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <?php $sel_query=mysqli_query($conn, "select * from admin where admin_id='$idmodal'")or die(mysql_error($conn)); $selrow=mysqli_fetch_array($sel_query);?>
  <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">Modal title</h4>
      </div>
      <div class="modal-body">
        <div class="panel panel-info" style="text-align:center;">
          <div class="panel-heading">
            <h4>Staff Details</h4>
          </div>
          <div class="panel-body">
            <div class="row">
              <div class="col-lg-6">
                <div class="form-group">
                  <label>Staff ID</label>
                  <p>
                    <?php echo $selrow[ 'staff_no']?>
                  </p>
                </div>
                <div class="form-group">
                  <label>Name</label>
                  <p>
                    <?php echo $selrow[ 'adm_name']?>
                  </p>
                </div>
                <div class="form-group">
                  <label>Services | Department</label>
                  <p>
                    <?php echo $selrow[ 'department']?>
                  </p>
                </div>
              </div>
              <!-- /.col-lg-6 (nested) -->
              <div class="col-lg-6">
                <div class="form-group">
                  <label>Username</label>
                  <p>
                    <?php echo $selrow[ 'username']?>
                  </p>
                </div>
                <div class="form-group">
                  <label>Password</label>
                  <p>
                    <?php echo $selrow[ 'password']?>
                  </p>
                </div>
                <div class="form-group">
                  <label>Date</label>
                  <p>
                    <?php echo $selrow[ 'date_added']?>
                  </p>
                </div>
              </div>

            </div>

          </div>

        </div>
      </div>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>
  <!-- /.modal-content -->
</div>

问题是没有任何效果,我也不知道从哪里开始. 感谢帮助.

The problem is nothing works, and i don't know where to start. Appreciate for the help.

推荐答案

<a></a>中创建一个类openModal.在<script></script>中使用此类可获取data-id

Create one class openModal in <a></a>. Use this class in <script></script> to get data-id

<?php  while($row = mysqli_fetch_array($adm_query,MYSQLI_ASSOC)){
    $id = $row['admin_id'];  ?>
        <tr>
            <td style="text-align:center"><?php echo $row['adm_name']; ?></td>
            <td width="150" style="text-align:center"><?php echo $row['staff_no']; ?></td>
            <td width="120" style="text-align:center"><?php echo $row['department']; ?></td>
            <td width="138" style="text-align:center;">                                 
                <a class="btn btn-outline btn-info openModal" data-toggle="modal" data-target="#myModal" data-id="<?php echo $row['admin_id']?>">
                    <i class="fa fa-search-plus"></i>
                </a>
            </td>
        </tr>
<?php }?>

将此代码放在下面的同一页面中.

Place this code in the same page below.

<div style="margin-top:5%;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content"></div>
    </div>
</div>

JS (在此处传递了data-id=...)

<script>
  $('.openModal').click(function(){
      var id = $(this).attr('data-id');
      $.ajax({url:"ajax_modal.php?id="+id,cache:false,success:function(result){
          $(".modal-content").html(result);
      }});
  });
</script>

ajax_modal.php (在同一目录 ajax_modal.php 中创建一个页面.如果要更改此页面名称.也请更改<script></script>标记.两者都相关.)

ajax_modal.php (Create one page in same directory ajax_modal.php. If you are looking to change this page name. Change in <script></script> tag too. Both are related.)

<?php 

// Get `id` from `<script></script>`
$id = $_GET['id'];

$sel_query=mysqli_query($conn, "select * from admin where admin_id='$id'") or die(mysql_error($conn)); 
$selrow=mysqli_fetch_array($sel_query,MYSQLI_ASSOC);
?>

<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  <h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
  <div class="panel panel-info" style="text-align:center;">
    <div class="panel-heading">
      <h4>Staff Details</h4>
    </div>
    <div class="panel-body">
      <div class="row">
        <div class="col-lg-6">
          <div class="form-group">
            <label>Staff ID</label>
            <p>
              <?php echo $selrow[ 'staff_no']?>
            </p>
          </div>
          <div class="form-group">
            <label>Name</label>
            <p>
              <?php echo $selrow[ 'adm_name']?>
            </p>
          </div>
          <div class="form-group">
            <label>Services | Department</label>
            <p>
              <?php echo $selrow[ 'department']?>
            </p>
          </div>
        </div>
        <!-- /.col-lg-6 (nested) -->
        <div class="col-lg-6">
          <div class="form-group">
            <label>Username</label>
            <p>
              <?php echo $selrow[ 'username']?>
            </p>
          </div>
          <div class="form-group">
            <label>Password</label>
            <p>
              <?php echo $selrow[ 'password']?>
            </p>
          </div>
          <div class="form-group">
            <label>Date</label>
            <p>
              <?php echo $selrow[ 'date_added']?>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

有关更多信息,请单击此处

For more info, click here

  1. how-to-pass-current-row -value-in-modal
  2. passing-data-via-modal -bootstrap-and-getting-php-variable
  3. bootstrap-modal-and-passing-value
  1. how-to-pass-current-row-value-in-modal
  2. passing-data-via-modal-bootstrap-and-getting-php-variable
  3. bootstrap-modal-and-passing-value
  4. show-data-based-of-selected-id-on-modal-popup-window-after-click-a-button-php-my

这篇关于使用SQL和amp;将数据从页面传递到引导模式的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆