模型每次显示第一行数据

时间:2016-06-24 11:43:01

标签: php html5

模型只显示每次点击的第一行数据。我该如何解决这个问题?

我使用php while循环显示了一个记录表。另外,一行有一个按钮,它是View按钮。点击此按钮后,我想显示该ID的信息。

<div class="row">
    <div class="col-xs-12">
        <div class="panel">
            <header class="panel-heading">
                Subject Material Detail View
            </header>
            <div class="panel-body table-responsive">
                <div class="box-tools m-b-15">
                    <div class="input-group">
                        <input type="text" name="table_search" class="form-control input-sm pull-right" style="width: 150px;" placeholder="Search"/>
                        <div class="input-group-btn">
                            <button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
                        </div>
                    </div>
                </div>
                <table class="table table-hover">
                    <tr>
                        <th>No.</th>
                        <th>User</th>
                        <th>Subject</th>
                        <th>Title</th>
                        <th>Description</th>
                        <th>Modified On</th>
                    </tr>


                    <?php

                        include("includes/config.php");
                        global $con;

                        $get_sm = ("select * from m_study_material");
                        $run_sm = mysqli_query($con, $get_sm);

                        $i = 0;
                        while ($row_sm = mysqli_fetch_array($run_sm)){
                            $subm_id = $row_sm['sm_id'];
                            $subm_created = $row_sm['created_by'];
                            $subm_subject = $row_sm['sm_subject'];
                            $subm_title = $row_sm['sm_title'];
                            $subm_desc = $row_sm['sm_description'];
                            $subm_modified = $row_sm['modified_on'];
                            $subm_image = $row_sm['sm_image'];

                    ?>  

                    <tr><?php echo $subm_id; ?>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $subm_created; ?></td>
                        <td><?php echo $subm_subject; ?></td>
                        <td><?php echo $subm_title; ?></td>

                        <td>

                        <a href="#myModal" data-toggle="modal" target="<?php echo $subm_id; ?>" class="btn btn-xs btn-success">
                            View
                        </a>

        <!-- View Modal starts Here-->
              <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
                  <div class="modal-dialog">
                      <div class="modal-content">
                          <div class="modal-header">
                              <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                              <h4 class="modal-title">Description</h4>
                          </div>
                          <div class="modal-body">

                                      <p class="help-block">

                                      <?php echo $subm_desc; ?>

                                      </p>

                          </div>
                      </div>
                  </div>
              </div>
        <!-- View Modal ends Here-->        
                </td>

                <td><span class="label label-success"><?php echo $subm_modified; ?></span></td>
            </tr>   

            <?php $i++; } ?>


                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div>
</div>

2 个答案:

答案 0 :(得分:2)

我认为这是因为你的所有模态都有相同的ID(&#34; #myModal&#34;)。因此,每次按钮点击都会召唤一个具有相同ID的模态(我怀疑它只显示第一个)。 HTML元素应具有唯一ID,以使页面正常工作。我也不认为&#34;目标&#34;您的超链接上的属性执行您认为它的功能 - 在此查找HTML规范。

我会做这样的事情:

<a href="#myModal_<?php echo $subm_id; ?>" data-toggle="modal" class="btn btn-xs btn-success">
                        View
                    </a>

    <!-- View Modal starts Here-->
          <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal_<%?php echo $subm_id"; ?>" class="modal fade">
              <div class="modal-dialog">

...等

答案 1 :(得分:0)

例如,尝试在模式名称后附加唯一ID

<div class="modal fade" th:id="'singleDeleteModal'+${loan.loanApplicationNumber}" tabindex="-1" role="dialog" aria-labelledby="singleDeleteModalLabel" aria-hidden="true">....

并这样称呼:

<a data-toggle="modal" th:data-target="'#viewModal'+${loan.loanApplicationNumber}">

查看更多