Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t使用yii打印具有5个表联接的用户的数据_Php_Yii - Fatal编程技术网

Php Can';t使用yii打印具有5个表联接的用户的数据

Php Can';t使用yii打印具有5个表联接的用户的数据,php,yii,Php,Yii,我是Yii的初学者。现在做一个工地。我想用5个表的内部连接打印用户数据。表格包括用户,求职者档案,求职档案,位置,类别。我的控制器是sitecontroller,我的视图文件是one\u jobseker.php 我的错误是 "Undefined index: name C:\wamp\www\yii_new\jobsite_orginal\protected\modules\admin\views\site\one_jobseeker.php(11)" var_dump shows ar

我是Yii的初学者。现在做一个工地。我想用5个表的
内部连接打印用户数据。表格包括
用户
求职者档案
求职档案
位置
类别
。我的控制器是
sitecontroller
,我的视图文件是
one\u jobseker.php

我的错误是

"Undefined index: name
C:\wamp\www\yii_new\jobsite_orginal\protected\modules\admin\views\site\one_jobseeker.php(11)"
var_dump shows

  array (size=1)
  0 => 
  array (size=22)
  'id' => string '1' (length=1)
  'name' => string 'jobseeker' (length=9)
  'email' => string 'jobseeker@gmail.com' (length=19)
  'password' => string 'ee33e27629d97b8da3cf77fedf1c349a669ca1ff' (length=40)
  'role' => string 'user' (length=4)
  'status' => string '1' (length=1)
  'created' => string '2014-04-11 11:48:05' (length=19)
  'modified' => string '2014-04-11 11:48:05' (length=19)
  'user_id' => string '15' (length=2)
  'contact_no' => string '342488888' (length=9)
  'gender' => string 'F' (length=1)
  'dob' => string '2014-04-08' (length=10)
  'mstatus' => string 'S' (length=1)
  'address' => string 'yyy' (length=3)
  'location_id' => string '1' (length=1)
  'title' => string 'IT, Computer Science' (length=20)
  'key_skills' => string 'php,mysqls' (length=10)
  'experience' => string '2225' (length=4)
  'salary' => string '300005' (length=6)
  'resume' => string 'Blue hills585.jpg' (length=17)
  'category_id' => string '1' (length=1)
  'description' => string 'Information Technology, Computer Science' (length=40)
控制器

   public function actionone_jobseeker()
  {
      $id  =$_GET['id'];
     $item = Yii::app()->db->createCommand()
     ->select('*')
     ->from('user u')
     ->join('job_seeker_profile s','u.id = s.user_id')
      ->join('job_profile j','u.id = j.user_id')
      ->join('location l','l.id = s.location_id')
      ->join('category c','c.id = j.category_id')
      ->where('u.id=:id', array(':id'=>$id))
     ->order('u.id')
        ->queryAll();
       $this->render('one_jobseeker',array('item' =>$item));
   }
查看-one_jobseker.php

  <div>
  <div style="float:right;margin-right:285px;">
  <h3 align="left" style="margin-left:-480px;">Jobseeker Detail</h3>
 <table  border="1" align="left" >
 <tr>
 <td>Name:</td>
 <td><?php echo $item['name'];  ?></td>
 </tr>
 </table>
 </div>
</div>

求职者详细信息
姓名:
有人帮我吗?


 <?php echo $item[0]['name'];  ?> 

将此代码添加到one_jobseker.php中

正如@DCoder所指出的,您在控制器中使用的是
queryAll()
,它返回一个数组,而不管它只包含一行

  <div>
  <div style="float:right;margin-right:285px;">
  <h3 align="left" style="margin-left:-480px;">Jobseeker Detail</h3>
 <table  border="1" align="left" >
 <tr>
 <td>Name:</td>
 <td><?php echo $item['name'];  ?></td>
 </tr>
 </table>
 </div>
</div>
当使用已知仅返回单行的条件时,请改用
queryRow()

$item = Yii::app()->db->createCommand()
 ->select('*')
 ->from('user u')
 ->join('job_seeker_profile s','u.id = s.user_id')
  ->join('job_profile j','u.id = j.user_id')
  ->join('location l','l.id = s.location_id')
  ->join('category c','c.id = j.category_id')
  ->where('u.id=:id', array(':id'=>$id))
 ->order('u.id')
    ->queryRow();

您可以使用
queryAll()
,它返回一个DB记录数组,而不是一个DB记录数组
var_dump
甚至显示了一个数组中只有一条记录,而不是一条记录。我想打印特定用户的数据,条件user_id='$id'即一行。Dcoder,你能帮我吗。。