在buttotn点击不同行的弹出窗口中加载不同的数据

时间:2016-07-12 09:55:34

标签: php codeigniter

我有一个表格,显示从数据库中获取的多行数据。

View of my actual page

每一行都有一个按钮。所以我想要的是,当我点击按钮时,它应该显示一个弹出窗口,并显示该特定行的数据。 例如,当我点击第一行的按钮时,将显示弹出第一行的数据。如果我点击第二行的按钮,将显示第二行的数据。

问题是,当我点击第一行或第二行的按钮时,我在两个不同行的弹出窗口中获得相同的数据。

popup for first and second row both give same result which is the data of the first row

那么,如何在与不同行相关的每个弹出窗口中获取不同的数据?

这是我的观察代码,其中我从控制器获取了值并显示

CONTROLLER

public function get_job()
        {
            $data['result'] = $this->user_model->view_job();
            if (!empty($data['result'])) 
            {
                $this->load->view('admin_view',$data);
            }
            else
            {
                $email = $_SESSION['email'];
                $data['result'] = $this->user_model->get_username($email);
                $this->load->view('no_job',$data);
            }
        }

MODEL

//To get recently added jobs by inner join
    public function view_job()
    {
        $this->db->select('add_job.*, crm_accounts.company');
        $this->db->from('add_job');
        $this->db->join('crm_accounts', 'add_job.cid = crm_accounts.id', 'inner');
        $this->db->where('add_job.status', 'NEW');
        $query = $this->db->get();
        return $query->result_array();

    }

查看

<table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>Id</th>
                        <th>Job Id</th>
                        <th>Job Name</th>
                        <th>Company Name</th>
                        <th>Company Id</th>
                        <th>More</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                      <?php
                        foreach ($result as $object) 
                        {
                      ?>
                        <td><?php echo $object['id']?></td>
                        <td><?php echo $object['job_id']?></td>
                        <td><?php echo $object['job_name']?></td>
                        <td><?php echo $object['company']?></td>
                        <td><?php echo $object['cid']?></td>
                        <td>
                          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#MyModal">
                            Details
                          </button>
                        </td>
                          </tr>
                          <div id="MyModal" class="modal fade" role="dialog">
                            <div class="modal-dialog">
                              <div class="modal-content">
                                <div class="modal-header">
                                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                                  <div class="modal-title"><h3>Company Name :<?php echo $object['company']?></h3></div>
                                </div>
                                <div class="modal-body">
                                  <h3>Id:           <?php echo $object['id']?></h3>
                                  <h3>Job Name:     <?php echo $object['job_name']?></h3>
                                  <h3>Job Id:       <?php echo $object['job_id']?></h3>
                                  <h3>Paper Size:   <?php echo $object['paper_size']?></h3>
                                  <h3>Paper Type:   <?php echo $object['paper_type']?></h3>
                                  <h3>Cutting Size: <?php echo $object['cutting_size']?></h3>
                                  <h3>Sheet:        <?php echo $object['sheet']?></h3>
                                  <h3>Lamination:   <?php echo $object['lamination']?></h3>
                                  <h3>Print Type:   <?php echo $object['print_type']?></h3>
                                  <h3>Ctp By:       <?php echo $object['ctp_by']?></h3>

                                </div>
                                <div class="modal-footer">
                                <form method="post" action="admin_view">
                                  <button type="button" name="accepted" value="accept" class="btn btn-success">Accept Job</button>
                                </form>
                                  <button type="button" class="btn btn-danger" data-dismiss="modal">Reject Job</button>
                                  <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
                                </div>
                                <?php } ?>
                              </div>
                            </div>
                          </div>
                        </td>

                    </tbody>

                  </table>

2 个答案:

答案 0 :(得分:2)

每次点击不同行时,同一模态的原因是每个模态的ID相同。

您需要做的是更改e.OriginalSource对于每一行,模态是不同的。为此,请附加Visualdata-target或模式的DIV ID之后的行。

像这样,

您的按钮代码看起来像这样,

counter

Modal的代码看起来像这样,

ID

答案 1 :(得分:0)

.card-container {
width: 496px;
}