Php 如何在Codeigniter中使用modal,使用单独的数据和特定的id?
我有一个视图页面(ikhtisar_视图)。当我点击一个ID时,它显示modal(链接到ikhtisar/detail)只包含该ID的数据 这是我的ikhtisar视图td(包含我可以点击查看详细信息的数据): 这是我的模型函数:Php 如何在Codeigniter中使用modal,使用单独的数据和特定的id?,php,codeigniter,Php,Codeigniter,我有一个视图页面(ikhtisar_视图)。当我点击一个ID时,它显示modal(链接到ikhtisar/detail)只包含该ID的数据 这是我的ikhtisar视图td(包含我可以点击查看详细信息的数据): 这是我的模型函数: public function detail() { $this->load->model('ikhtisar_model'); $detailr = $this->ikhtisar_model->trx(); $d
public function detail()
{
$this->load->model('ikhtisar_model');
$detailr = $this->ikhtisar_model->trx();
$data['detail'] = $detailr;
$this->load->view('ikhtisar/trx_view',$data);
}
public function trx()
{
$ikh = $this->input->post('id');
$this->db->select('t.id_transaksi AS id, t.tgl_transaksi AS tgl, t.id_member AS memberid, t.nama AS nama, p.kode_produk AS kode, tp.hp_tujuan AS nohp, d.nama AS nama2, t.saldo_awal AS saw, tp.hpp AS hpp, t.saldo_akhir AS sak, tp.laba AS laba, t.ket AS ket, sr.ket AS ket2, sr.jenis AS sj', FALSE)
->from('transaksi_pulsa tp')
->join('transaksi t','tp.id_transaksi=t.id_transaksi', 'left')
->join('produk p','tp.kode_produk = p.kode_produk', 'left')
->join('set_report sr','t.status=sr.jenis', 'left')
->join('distributor d','tp.id_distributor=d.id_distributor and tp.com=d.com', 'left')
->where('t.id_transaksi', $ikh);
$ikhtisar = $this->db->get();
return $ikhtisar;
}
最后这是我的trx_view.php:
<table class="table table-striped table-hover table table-bordered" id="ikhtisar">
<thead style="display: table-header-group; vertical-align: middle; border-color: inherit;">
<tr>
<th>Status</th>
<th>No</th>
<th>Tanggal</th>
<th>Kode RS</th>
<th>Nama RS</th>
<th>Produk</th>
<th>Tujuan</th>
<th>Stok</th>
<th>Harga</th>
<th>Saldo Akhir</th>
<th>Laba</th>
</tr>
</thead>
<tbody>
<?php foreach($ikhlist->result_array() as $ikh): ?>
<tr>
<!--<td><a href="http://localhost/modal/modal.php" data-toggle="modal" data-target="#myModal"><?php echo $ikh['id']?></a></td>-->
<td style="font-size: 15px;" align="center"><?php if($ikh['sj'] == '1'){?><span><i class="glyphicon glyphicon-ok green"></i></span><?php }elseif($ikh['sj'] == '2'){ ?><span><i class="glyphicon glyphicon-remove red"><?php }else{ ?><span><i class="glyphicon glyphicon-question-sign yellow"><?php }?></i></span></td>
<td><?php echo $ikh['id']?></td>
<td><?php echo $ikh['tgl']?></td>
<td><?php echo $ikh['memberid']?></td>
<td><?php echo $ikh['nama']?></td>
<td><?php echo $ikh['kode']?></td>
<td><?php echo $ikh['nohp']?></td>
<td><?php echo $ikh['nama2']?></td>
<td class="text-right"><?php echo number_format($ikh['hpp'], 0, ",", ".")?></td>
<td class="text-right"><?php echo number_format($ikh['sak'], 0, ",", ".")?></td>
<td><?php echo $ikh['laba']?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
地位
不
唐加尔
科德RS
纳马RS
普罗杜克
图娟
斯托克
哈尔加
萨尔多·阿基尔
拉巴
但是我只得到了一个没有数据的页面(trx_view.php)。它只包含标题。那么,如何显示正确的数据呢?在ikhtisar_视图中(单击id查看详细信息之前),没有问题。尝试自己调试代码, 尝试使用打印模型中的查询
echo $this->db->last->query()
尝试在上面接收的查询数据库上运行该查询,并检查是否正在获取数据
然后尝试在视图中打印
$detail
变量,并检查您的视图是否实际获取了数据。如果我在ikhtisar\u视图中使用此变量:
<td>
<form method="post" action="<?php echo base_url();?>index.php/ikhtisar/detail">
<input type="hidden" name="id"
value="<?php echo $ikh['id']; ?>" />
<input type="submit" value="<?php echo $ikh['id']; ?>" />
</form>
</td>
如果t
id\u transaksi
=0,那么问题出在我的模型函数中,$ikh不正确,没有数据。有什么想法吗?在$ikhtisar=$this->db->get()之后,在模型函数中回显$this->db->last->query(),,,,,它将打印数据库查询,并在数据库上运行它。是的,Nishant,我已经这样做了,最后一个查询是上面的执行模型脚本函数trx()。但是,$ikh(我点击的这个平均id)=0。我认为:$ikh=$this->input->post('id');不对。但我还是不知道正确的答案是什么。
<td>
<form method="post" action="<?php echo base_url();?>index.php/ikhtisar/detail">
<input type="hidden" name="id"
value="<?php echo $ikh['id']; ?>" />
<input type="submit" value="<?php echo $ikh['id']; ?>" />
</form>
</td>
<td><a href="<?php echo base_url();?>index.php/ikhtisar/detail" class='iframe' name="id">
<input name="id" value="<?php echo $ikh['id']; ?>" />
</a></td>