使用CakePHP的结果构造表

使用CakePHP的结果构造表,cakephp,Cakephp,我有一个这样的疑问 $report_attrid=$this->Report->find('all',array('conditions'=>array('Report.report_id'=>$report_id,'Report.user_id'=>$userId))); foreach($report_attrid as & $reportattrid): $reportattrid['Report']['attr']=

我有一个这样的疑问

     $report_attrid=$this->Report->find('all',array('conditions'=>array('Report.report_id'=>$report_id,'Report.user_id'=>$userId)));


   foreach($report_attrid as & $reportattrid):

      $reportattrid['Report']['attr']=$this->Attribute->find('all',array('fields'=>array('Attribute.id','Attribute.label'),'conditions'=>array('Attribute.id'=>$reportattrid['Report']['attribute_id'],'Attribute.form_id'=>$report_form_id),'order'=>'Attribute.sequence_no'));

      $reportattrid['Report']['value']=$this->Result->find('all',array('fields'=>array('Result.label','Result.value','Result.submitter_id','Result.submitter'),'conditions'=>array('Result.attribute_id'=>$reportattrid['Report']['attribute_id'],'Result.form_id'=>$report_form_id),'order'=>'Result.id'));



   endforeach;


        $this->set('Report_attrid',$report_attrid);
1.$report\u attrid的第一个将为我提供报告所需的所有数据

作为

2.然后foreach attribute_id,我从第二个查询$reportattrid['Report']['attr']中的属性表中获取属性标签

三,。 然后Foreach Reports attribute_id我正试图使用$reportattrid['Report']['value']从结果表中获取条目,它给出

首先,当属性_id=69时,它返回2行

作为

然后属性_id=72返回2行

作为

一切正常,但现在

我正在尝试构建一个表以在视图中显示

使用

但是我需要这张桌子

       Firstname experience
        A           C
        B           D

怎么做??请建议我…

我想查看您的报告、属性和结果的模型代码。我认为您可以更好地建立关系,通过一次呼叫返回数据

从代码看,似乎:

属性有多个报告&报告属于属性 属性有多个结果&结果属于属性 如果您在模型中设置了这些关系,那么您只需要打一个电话,所有相关记录也会显示出来

一旦你完成了模型,让我知道,我们可以看看下一步

    id form_id attribute_id value
     1    24       69         A
     2    24       69         B
        id form_id attribute_id value
        3    24       72         C
        4    24       69         D
  <table id="sampletable">
  <thead>
       <?php foreach ($Report_attrid as $report1): ?>

 <th id="headerid<?php echo $report1['Report']['attr'][0]['Attribute']['id'];?>"><?php echo $report1['Report']['attr'][0]['Attribute']['label'];?>
    </th>                 

      <?php endforeach; ?>
  <?php foreach ($Report_attrid as $report2): ?>

                  <tr>     <?php foreach ($report2['Report']['value'] as $report3): ?>

                              <td> <?php echo $report3['Result']['value'];?>   </td>

                          <?php endforeach; ?>
                 </tr>

 <?php endforeach; ?>
</table>
     Firstname experience
       A           B
       C           D
       Firstname experience
        A           C
        B           D