1

我想链接员工的名字.....当我点击任何名字然后显示他的详细信息......我创建这个代码..bt一些错误“试图获取非对象的属性” ......请帮助我......

1.控制器

function abc($id = 0)    
{
     $this->load->model('emp_model');
     $data['rows'] = $this->emp_model->get();
     $this->load->view('personal_emp',$data);
}

2.型号

function get($id)
{
    $this->load->database();   
    return $this->db->get_where('employee',array('id'=>$id))->row_array();        
}

3.views

<table border="1" height="200" width="200" bordercolor="#003366" align="center">

<tr>
    <th>ID</th></td>
    <th>NAME</th>
    <th>Fathet Name</th>
    <th>Dob</th>
    <th>Qualification</th>
    <th>Identity Type</th><th>Identity No</th>
    <th>Gender</th>
    <th>Email</th>
    <th colspan='2'>Action</th>
</tr>
<?php foreach($rows as $r)
{
  echo "<tr>";
  echo "<td>". $r->id ."</td>";
  echo "<td>". $r->name ."</td>";
  echo "<td>". $r->father_name ."</td>";
  echo "<td>". $r->dob ."</td>";
  echo "<td>". $r->qualification ."</td>";
  echo "<td>". $r->identity_type ."</td>";
  echo "<td>". $r->identity_no ."</td>";
  echo "<td>". $r->gender ."</td>";
  echo "<td>". $r->email ."</td>";
  echo "<td>". anchor('employee/input/'.$r->id,'Edit') ."</td>";    
  echo "<td>". anchor('employee/del/'.$r->id,'Delete') ."</td>";
  echo "</tr>"; 
  echo "<br>"; 
}
?>
</table>
4

1 回答 1

1

对于初学者,您需要为变量命名,在这种情况下,即数组键。然后你需要调用正确的方法。不是general()但是get()

function abc($id = 0)    
{
     $this->load->model('emp_model');
     $data['rows'] = $this->emp_model->get();
     $this->load->view('personal_emp',$data);
}

对方法稍作修改

function get($id)
{
   $this->load->database();   
   return $this->db->get_where('employee',array('id'=>$id))->result();        
}

希望这可以帮助。玩得开心!

于 2012-06-30T19:02:54.733 回答