我正在从事Codeigniter并生成测试报告。每个患者都有各种测试,每个测试都属于特定部门。例如葡萄糖,尿素,肌酐属于生物化学部门,而TLC,PLT属于血液学。我希望明智地将这些报告给部门,但无法做到这一点。我在视图中使用foreach循环。这是我的模型代码
public function pending_reports()
{
$data = array();
$posts = array();
$posts = $this->db->select()->order_by('id', 'ASC')->where('status',
'Pending')->get('reports')->result_array();
if( is_array( $posts ) && count( $posts ) > 0 ){
foreach( $posts as $key=>$each ){
$test_reports_info = array();
$test_reports_info = $this->db->select()->order_by('id', 'ASC')-
>where('report_id', $each['id'])->get('test_reports')->result_array();
if( is_array ( $test_reports_info ) ){
$posts[$key]['test_reports_info'] = $test_reports_info;
}
}
return $posts;
}
这是我的查看代码
<div id="create_report_div<?php print_r($info['id']);?>" style="margin-top:
20px;width: 100%;float: center;">
<?php if( count($info['test_reports_info'][0]) ): ?>
<?php foreach ($info['test_reports_info'] as $test_info):?>
<?php $str=("department/".$test_info['test_department'].'.php');?>
<?php include(preg_replace('/\s+/', '', $str)); ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
</div>
报告应将所有生物化学测试归类为“血液学”下的“生物化学和血液学测试”以及“血清学”下的所有血清学测试。我该怎么办,请帮助我
在这里我修改了上面的代码以对测试进行排序
<?php if( in_array('dep_biochemistry', $info['test_reports'][3]) ): ?>
<div> BIOCHEMISTRY</div>
<?php foreach ($info['test_reports'] as $test_info):?>
<?php if ($test_info['test_department']=='dep_biochemistry'): ?>
<?php $str=("department/".$test_info['test_department'].'.php');?>
<?php include(preg_replace('/\s+/', '', $str)); ?>
<?php else: ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
<?php if( in_array('dep_hematology', $info['test_reports'][3]) ): ?>
<div> HEMATOLOGY</div>
<?php foreach ($info['test_reports'] as $test_info):?>
<?php if ($test_info['test_department']=='dep_hematology'): ?>
<?php $str=("department/".$test_info['test_department'].'.php');?>
<?php include(preg_replace('/\s+/', '', $str)); ?>
<?php else: ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
<?php if( in_array('dep_serology', $info['test_reports'][3]) ): ?>
<div> BIOCHEMISTRY</div>
<?php foreach ($info['test_reports'] as $test_info):?>
<?php if ($test_info['test_department']=='dep_serology'): ?>
<?php $str=("department/".$test_info['test_department'].'.php');?>
<?php include(preg_replace('/\s+/', '', $str)); ?>
<?php else: ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
,但结果仍然不一致。我得到血液学结果,在其他情况下我得到错误 消息:未定义的偏移量:3
Filename: management/pending_reports_admin.php
Line Number: 93
在这里,我知道我的数组不为空。请帮助我