我想创建一个变量,其中包含使用CodeIgniter在PHP中使用foreach创建的表之一的数据。 tersebuat变量将用于查看数据库中数据的详细信息,我将以弹出窗口的形式显示这些数据。
<table class="table table-striped table-bordered table-hover" id="ab">
<thead>
<tr>
<th> # </th>
<th> Invoice </th>
<th> Product </th>
<th> date </th>
<th> suplier </th>
<th> Description </th>
<th> Detail </th>
</tr>
</thead>
<tbody>
<?php $numb=0;foreach($proses as $isi){$numb++; ?>
<tr>
<td> <?php echo $numb;?> </td>
<td> <?php echo $isi->invoice;?> </td>
<td> <?php echo $isi->name;?> </td>
<td> <?php echo $isi->date;?> </td>
<td> <?php echo $suplier;?> </td>
<td> --- </td>
<td class="text-center">
<a class="btn blue btn-outline sbold" data-toggle="modal" href="#full"> Detail </a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
程序的示例输出:
1|000012|Noodle|03-Mar-2016|Suplier01|--|(Detail)|
2|000044|Rice |05-Mar-2016|Suplier03|--|(Detail)|
如何在点击invoice details
时将发票编号000012
输入到变量(例如,$invoice
)中?
我假设您希望在模态中显示详细信息。
为此,您可以:
- 使用 PHP 打印出模态,并且每个表行有一个模态。
- 或者,将变量作为数据属性,例如按钮本身。
对于 2,例如:
<a data-invoice="<?php echo $isi->invoice;?>" class="btn blue btn-outline sbold" data-toggle="modal" href="#full"> Detail </a>
然后使用 jquery 检测按钮单击并设置模态的 html 值。
$('a.btn').click(function(){
$('.modal <your own selector here>').html($(this).data('invoice'));
});