안녕하세요 개발자 내 애플리케이션에서 보고서를 인쇄해야합니다. 나는 codeigniter를 사용하고있다. 내 데이터베이스에 이런 식탁이있어.foreach에서 중복 값 제거
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
처럼 인쇄 할 데이터
,691를 표시 CODELpublic 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);
}
및 뷰 내 모델입니다 363,210
<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를 사용하여 테이블의 모든 데이터를 얻고 그것은 .. –
그게 당신이하고있는 일이고, 우리가 사용한 코드를 보여 주며, 무엇을 낳았으며, 왜 당신이 원한 것이 아니 었는지 말해주지 마십시오. 귀하의 게시물 (코멘트로 답변하지 않음)로 편집 –