2012-06-04 97 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; 
     }