我正在使用项目中数据库中的循环数据制作模态,但我想通过选择查询GROUP BY
颜色where id = modal id
来获取数据库中的所有数据,但我的控制器无法获取模态 ID,这使得它在选择时出错。 请帮我修复它...谢谢
这是视图代码:
<table class="table table-bordered table-hover table table-sm" id="dataTable" width="100%" cellspacing="0">
<thead class="warna-header">
<tr>
<th rowspan="2" style="vertical-align:middle;text-align:center;">Tipe</th>
<th colspan="3" class="text-center bg-danger">1</th>
<th colspan="3" class="text-center bg-warning">2</th>
<th colspan="3" class="text-center bg-success">3</th>
<th rowspan="2" style="vertical-align:middle;text-align:center;" class="text-center">ACTION</th>
</tr>
</thead>
<tbody>
<?php foreach ($st_mobil as $st_mbl) : ?>
<tr>
<td style="font-size:12px;color:black;"><?php echo $st_mbl['jenismobil']; ?></td>
<td style="font-size:12px;color:black;text-align:center;"><?php echo $st_mbl['beli1']; ?></td>
<td style="font-size:12px;color`enter code here`:black;text-align:center;"><?php echo $st_mbl['jual1']; ?></td>
<td style="font-size:12px;color:black;text-align:center;"><?php echo $st_mbl['sisa1']; ?></td>
<td class="text-center">
<a href="" class="btn btn-success btn-sm view_detail" data-toggle="modal" title="Edit Data" data-target="#ViewStockMobilModal<?php echo $st_mbl['id']; ?>">
<span class="icon text-white-10">
<i class="fas fa-search"></i>
</span>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
-- Modal View
<?php foreach ($st_mobil as $st_mbl) : ?>
<div class="modal fade bd-example-modal-lg" id="ViewStockMobilModal<?php echo $st_mbl['id']; ?>" tabindex="-1" role="dialog"
aria-labelledby="ViewStockMobilModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header bg-primary">
<h5 class="modal-title" id="jenismobil" name="jenismobil">
<font color=white><?php echo $st_mbl['jenismobil']; ?></font>
</h5>
<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table class="table table-bordered table-striped table-sm">
<thead class="btn-primary">
<tr>
<th style="font-size:12px;" class="text-center bg-danger">ST</th>
<th style="font-size:12px;" class="text-center bg-danger">BK</th>
<th style="font-size:12px;" class="text-center bg-danger">BJ</th>
</tr>
</thead>
<?php foreach($view_detail as $vdt) : ?>
<tbody>
<tr>
<td style="font-size:12px;color:black;"><?php echo $vdt['warna']; ?></td>
<td style="font-size:12px;color:black;text-align:center;"><?php echo $vdt['st_in_1']; ?></td>
<td style="font-size:12px;color:black;text-align:center;"><?php echo $vdt['st_out_1']; ?></td>
</tr>
</tbody>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
这是控制器:
$data['st_mobil'] = $this->db->get('st_mobil')->result_array();
$id = $this->input->get($id); // i want to get the id of my modal
$data['view_detail'] = $this->stock_model->get_view_modal($id);
这是我的模型:
public function get_view_modal($id)
{
$query = "SELECT `id`,`jenismobil`,`warna`,`st_in_1`,`st_out_1`,`st_sisa_1`,`st_in_2`,`st_out_2`,`st_sisa_2`,`st_in_3`,`st_out_3`, st_sisa_3`
FROM `st_mobil`
GROUP BY `warna`
WHERE `id` = '$id'
";
return $this->db->query($query)->result_array();
}
当你得到 id 时 $id = $this->input->get('id'(;这应该像这样纠正。