【发布时间】:2014-11-03 15:27:13
【问题描述】:
您好开发人员我必须在我的应用程序中打印一份报告。我正在使用代码点火器。我的数据库中有一张这样的表。
Report Detail
---------------------------------------------------------------------------
ID Test_ID Description Description_Group Test_Name
---------------------------------------------------------------------------
1 117 value 1 group 1 Test 1
2 117 value 2 group 1 Test 1
3 4 another 1 group 2 Test 2
4 4 another 2 group 2 Test 2
5 4 another 3 group 2 Test 2
我想这样打印
desired print format
-----------------------------------------------
Description
-----------------------------------------------
**Test 1**
group 1
value 1
value 2
**Test 2**
group 2
another 1
another 2
another 3
这是我的模型代码
public function print_report($Patient_ID, $ID)
{
$query = $this->db->query('select a.ID, a.Description, a.Description_Group, a.Normal_Range, a.Measure_Unit,
b.Result_Value
from tbltestdefault a
inner join tblreportdetail b on a.ID = b.Test_Default_ID
where b.Patient_ID = '.$Patient_ID.' and b.Patient_Test_ID = '.$ID.'');
return $query->result_array();
}
控制器
public function print_report($ID, $Patient_ID, $Test_ID)
{
$data['patient'] = $this->Report_Model->getPatientinfo($Patient_ID);
$data['testname'] = $this->Report_Model->gettestnameonly($Test_ID);
$data['tests'] = $this->Report_Model->print_report($Patient_ID, $ID);
$this->load->view('report_view', $data);
}
以及显示数据的视图
<table class="table table-bordered">
<thead>
<tr>
<th> <h4>Description</h4>
</th>
<th> <h4>Result</h4>
</th>
<th> <h4>Units</h4>
</th>
<th> <h4>Normal Value</h4>
</th>
</tr>
</thead>
<tbody>
<?php foreach($tests as $t): ?>
<tr>
<td>
<?php echo $t['Description_Group']; ?>
<?php echo $t['Description']; ?>
</td>
<td><?php echo $t['Result_Value']; ?></td>
<td><?php echo $t['Measure_Unit']; ?></td>
<td><?php echo $t['Normal_Range']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
【问题讨论】:
-
好的,很酷。到目前为止,您为实现这一目标做了什么尝试? (我们不会为您编写代码,我们只是在这里帮助您找出您尝试的代码为什么不起作用)
-
我只是用 foreach 从表中获取所有数据并按原样显示..
-
不要告诉我这就是你在做什么,向我们展示你使用的代码,产生了什么,以及为什么你觉得这不是你想要的。已编辑到您的帖子中(未作为评论回复)
-
是的,当然..现在请看一下
-
这是非常好的附加信息;仍然缺少一点是它现在产生的让你觉得它做错事的东西。它是否显示正确的数据,格式错误?还是它完全显示了错误的数据?
标签: php mysql codeigniter foreach