<?php
$samgri = $this->crud_model->get_puja_samagri_by_puja_order($param1,$param);
foreach ($samgri as $row){
$puja_samagri = $row['puja_samagri'];
}
$puja_sam = explode(',', $puja_samagri);
foreach ($puja_sam as $samagri_id){
$samg = $this->crud_model->get_puja_samagri_by_id($samagri_id);
}
foreach ($samg as $row){
?>
<html>
<form action = '<?php echo site_url();?>/main/pdfdownload'>
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table id="customers2" class="table table-bordered datatable">
<thead>
<tr>
<th>S.NO</th>
<th>Items</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
<div style = 'text-align:right'>
<button type="submit" class="btn btn-primary">Download</button>
</div>
</form>
</html>
答案 0 :(得分:0)
<iframe>
现在print_r($ puja_samagri);死; //添加并查看它只是一个记录
所以在foreach中使用数组instaed ,即= $ puja_samagri []
<?php
$samgri = $this->crud_model->get_puja_samagri_by_puja_order($param1,$param);
foreach ($samgri as $row){
$puja_samagri = $row['puja_samagri'];
}
注意:在其他foreach中执行相同的操作只需定义数组,否则它只包含最后一个值...
答案 1 :(得分:0)
请先打印$samgri
变量并查看获得的结果。如果您的$samgri
包含结果数组,请使用以下代码更改您的代码。
<?php
$samgri = $this->crud_model->get_puja_samagri_by_puja_order($param1,$param);
$puja_samagri = [];
foreach ($samgri as $row){
$puja_samagri[] = $row['puja_samagri'];
}
if(!empty($puja_samagri))
{
foreach ($puja_samagri as $samagri_id){
$samg = $this->crud_model->get_puja_samagri_by_id($samagri_id);
}
foreach ($samg as $row){
}
?>
答案 2 :(得分:0)
您应该获取数组,如Codeigniter User Guide
中所述$query = $this->db->query("YOUR QUERY");
foreach ($query->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['body'];
}