jitu
jitu

Reputation: 9

how to get id from database by link

i wann link in name of employee.....when i click any name then show his details....i create this code..bt some error "Trying to get property of non-object"....pls help me......

1.controller

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

2.models

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>

Upvotes: 1

Views: 935

Answers (1)

Robert
Robert

Reputation: 1907

For starters, you need to get the variable a name, in this case, that is the array key. Then you need to call the right method. Not general() but get().

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

Slight modification of the method

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

Hope this helps. Have fun!

Upvotes: 1

Related Questions