2012-06-04 91 views
0
function empAll() 
{  
    $this->db->where('id',$id); 
    $q = $this->db->get('employee');   
    if($q->num_rows()>0) 
    {  
    foreach($q->result() as $rows) 
     {  
     $data[]=$rows; 
     } 
    return $data; 
} 

回答

1

一般来说,我们通过在URL ID:

BASE_URL()/的index.php/empAll/25。现在codeigniter automatecaly在方法中传递$ id = 25。在没有收到ID的情况下,它将分配ID为0,然后你不会得到这个错误。

function empAll() 
     {  
      $q = $this->db->where('id',$this->input->post('id'))  
         ->get('employee');   
      if($q->num_rows()>0) 
      {  
      foreach($q->result() as $rows) 
       {  
       $data[]=$rows; 
       } 
      } 
      return $data; 
     }