EllisLab text mark
Advanced Search
     
how to get id from database by link…pls help me…i use this code….but get error undefined rows…...
Posted: 30 June 2012 10:59 AM
Joined: 2012-06-16
9 posts

1.controller

function abc($id 0)    
{
     $this
->load->model('emp_model');
     
$data $this->emp_model->general();
     
$this->load->view('personal_emp',$data);

2.models

function get($id)
{
   $this
->load->database();   
   
$rows $this->db->get_where('employee',array('id'=>$id));
   return 
$rows->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
 
Posted: 30 June 2012 12:25 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-08-28
139 posts

$rows is not defined, you should fix your controller by writing this:

$data = array("rows" => $this->emp_model->general()); 

instead of $data = $this->emp_model->general();

Also, if you use $rows->row_array() in your model,
then you should use $r[“id”] instead of $row->id
row_array will return an array, while row will return an object

 Signature 

Homepage : http://www.getnocms.com
Github page : https://github.com/goFrendiAsgard/No-CMS

A free CodeIgniter based CMS-Framework, It is not just another CMS !!!

 
Posted: 01 July 2012 05:07 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-06-16
9 posts

ERROR SHOW WHAT IS THIS: Trying to get property of non-object

1.controller

function abc($id 0)
     
{
      $this
->load->helper('form'); 
   
$this->load->helper('html');
   
$this->load->model('emp_model');
     
$data = array("rows" => $this->emp_model->general());  
   if((int)
$id 0)
   
{
   $data[
'rows']=$this->emp_model->info1($id);
      
$data['fid']['value'$query['id'];
     
$data['fname']['value'$query['name'];
  
$data['ffather_name']['value'$query['father_name'];
  
$data['fdob']['value'$query['dob'];
  
$data['fidentity_type']['value'$query['identity_type'];
     
$data['fidentity_no']['value']$query['identity_no'];
     
$data['femail']['value']$query['email'];
   
}
   $this
->load->view('personal_emp',$data);
     

2.model

function info1($id)
    
{
     $this
->load->database();
     
$q =$this->db->get_where('employee');        
         
    if(
$q->num_rows()>0)
           
{    
             
foreach($q->result() as $rows)
              
{      
                $data[]
=$rows;
              
}
          
return $data;
           
}
    } 


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
 
Posted: 01 July 2012 06:29 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6707 posts
function abc($id 0)
{
    $this
->load->helper('form'); 
    
$this->load->helper('html');
    
$this->load->model('emp_model');

    
$data['general'$this->emp_model->general();  

    if((int)
$id 0)
    
{
        $data[
'rows']=$this->emp_model->info1($id);
        
$data['fid']['value'$query['id'];
        
$data['fname']['value'$query['name'];
        
$data['ffather_name']['value'$query['father_name'];
        
$data['fdob']['value'$query['dob'];
        
$data['fidentity_type']['value'$query['identity_type'];
        
$data['fidentity_no']['value']$query['identity_no'];
        
$data['femail']['value']$query['email'];
    
}

    $this
->load->view('personal_emp',$data);

 

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View