0

我的控制器

        $data= $this->Contact->find('all',array(
        'conditions' => array('Contact.User_id' => $id)));

    $this->loadModel('Calllog');
      foreach($data as $row){

      $mobile=  $row['Contact']['mobileNo'];
      $home=  $row['Contact']['homeNo'];
      $work=  $row['Contact']['workNo'];


      $recent=$this->Calllog->find('all',
          array('order'=>'Calllog.idCallLog DESC',
              'limit' => 1,
              'conditions' => array('Calllog.mobileNo' => array($mobile,$work,$home ),
                  'Calllog.User_id' => $id


              )));

    debug($recent);
      $this->set('recent',$recent);


    }

在我看来,我有这条线

  <?php  foreach($recent as $as): ?> <?php echo $as['Calllog']['mobileNo'];?>

但没有显示任何内容,甚至没有任何错误

我调试了我得到一行的结果意味着工作正常,我还转储了查询运行良好的 sql 查询,当我在 phpmyadmin 中运行此查询时,它给了我我想要的一行.. 但是为什么它没有在我的视图页面上回显结果

调试结果

      array(
      (int) 0 => array(
       'CallLog' => array(
       'idCallLog =>'3',
        'mobileNo'=>'12345'
         'User_id'=>'1'
          )))

然后在 4 行之后

         array()
4

1 回答 1

0

尝试这个

$data= $this->Contact->find('all',array(
        'conditions' => array('Contact.User_id' => $id)));

$recent = array();

$this->loadModel('Calllog');
foreach($data as $row){

  $mobile=  $row['Contact']['mobileNo'];
  $home=  $row['Contact']['homeNo'];
  $work=  $row['Contact']['workNo'];


  $recent[]=$this->Calllog->find('all',
          array('order'=>'Calllog.idCallLog DESC',
              'limit' => 1,
              'conditions' => array('Calllog.mobileNo' => array($mobile,$work,$home ),
                  'Calllog.User_id' => $id
          )));

}

$this->set('recent',$recent);
debug($recent);
于 2013-06-19T05:45:15.930 回答