• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i am a codeigniter biginner, i have two files in my view folder. logged _in_ area.php and personal_emp .php. design is

#1
[eluser]atulswe1[/eluser]
i got the error undifined index:id and name,,all of

views
1.logged_in_area


Code:
<table border="1" height="200" width="200" bordercolor="#003366" align="center">
      <tr><th>ID</th></td><th>NAME</th>&lt;?php /*?&gt;<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>&lt;?php */?&gt;</tr>
   &lt;?php
      foreach($rows as $r)
  
{
   echo "<tr>";
   echo "<td>". $r->id ."</td>";
   echo "<td>". anchor('employee/abc/',$r->name) ."</td>";
  
   echo "</tr>";
   echo "<br>";
}
   ?&gt;
   </table>

2.personal_emp

Code:
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>
   &lt;?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>";
}
   ?&gt;
   </table>

controller

Code:
function abc($id = 0)
     {
      $this->load->helper('form');
   $this->load->helper('html');
   $this->load->model('emp_model');
      $data['rows']=$this->emp_model->general();  
  
   $data['rows'] = $this->emp_model->info1($id);
    
   $this->load->view('personal_emp',$data);
     }

model

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

#2
[eluser]bclinton[/eluser]
Try a print_r($rows) in your view to see what your row array looks like.

If that doesn't help, look into logging in your controller and model.

#3
[eluser]cartalot[/eluser]
row array in the model might be an issue, but the bigger problem is -- you have an error, but you dont know where the error is from
solution -- error check each step

in your model, after the $query, make sure there is something there before returning,
otherwise return false. note this is also using query-row()
Code:
if ( $query->num_rows() == 1 ) { return $query->row(); }
else { return FALSE; }

in your controller - i'm showing an echo for debugging, never echo directly from controller for live site
Code:
// IF we did NOT ( the ! ) get something back from model then....
if (! $data['rows'] = $this->emp_model->info1($id) )  
{ echo 'there was an error using id number'. $id ;
// or show the form again or whatever needs to happen here
}
// Else Load the view, now knowing that something has been returned from database
else
{   $this->load->view('personal_emp',$data) ; }





Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.