title: Fatal error: Call to a member function num_rows() on a non-object
body: <p>Hihow r u all?</p>
  
  <p>I m trying to calculate basic salary with Particular employee_id but when i m trying to .. give me fatal error..</p>
  
  <p>Fatal error: Call to a member function num_rows() on a non-object in D:\wamp\www\template\application\models\salary.php on line 112</p>
  
  <p>my code is: model</p>
  
  <pre><code>&lt;?php
  class Salary extends Model
  {   
      /*
      Determines if a given person_id is a profile
      */
      function exists($salary_id)
      {
          $this-&gt;db-&gt;from('salary_scale');
          $this-&gt;db-&gt;where('id',$salary_id);
          $this-&gt;db-&gt;where('deleted',0);      
          $query = $this-&gt;db-&gt;get();
  
          return ($query-&gt;num_rows()==1);
      }
      /*
      Determines if a given employee_id is a employee
      */
      function exists_employee($employee_id)
      {
          $this-&gt;db-&gt;from('grade_history');
          $this-&gt;db-&gt;where('employee_id',$employee_id);
          $query = $this-&gt;db-&gt;get();
  
          return ($query-&gt;num_rows()==1);
      }
  
      /*
      Returns all the suppliers
      */
      function get_all()
      {
          $this-&gt;db-&gt;from('salary_scale');
          $this-&gt;db-&gt;where('deleted', 0);
          $this-&gt;db-&gt;order_by("name", "asc");
          return $this-&gt;db-&gt;get();
      }
  
          /*
           *
           *  Gets information about a particular employees salary
       */
      function grade_rules_info($salary_grade)
      {
          $this-&gt;db-&gt;from('salary_scale_rules');
          $this-&gt;db-&gt;where('salary_grade',$salary_grade);
          $query = $this-&gt;db-&gt;get();
  
          if($query-&gt;num_rows()==1)
          {
              return $query-&gt;row();
          }
          else
          {
              //Get empty base parent object, as $item_id is NOT an item
              $salary_obj=new stdClass();
  
              //Get all the fields from items table
              $fields = $this-&gt;db-&gt;list_fields('salary_scale_rules');
  
              foreach ($fields as $field)
              {
                  $salary_obj-&gt;$field='';
              }
  
              return $salary_obj;
          }
      }
  
          /*
           *
           *  Gets information about a particular employees salary
       */
      function get_info($employee_id)
      {
          $this-&gt;db-&gt;from('allowance');
          //$this-&gt;db-&gt;join('deductions', 'deductions.eid = allowance.eid');
          $this-&gt;db-&gt;where('employee_id',$employee_id);
          $query = $this-&gt;db-&gt;get();
  
          if($query-&gt;num_rows()==1)
          {
              return $query-&gt;row();
          }
          else
          {
              //Get empty base parent object, as $item_id is NOT an item
              $salary_obj=new stdClass();
  
              //Get all the fields from items table
              $fields = $this-&gt;db-&gt;list_fields('items');
  
              foreach ($fields as $field)
              {
                  $salary_obj-&gt;$field='';
              }
  
              return $salary_obj;
          }
      }
  
          /**
           * Gets information about a particular employees salary
           *
       **/
      function get_grade_info($employee_id)
      {
          $this-&gt;db-&gt;from('grade_history');
          $this-&gt;db-&gt;where('employee_id',$employee_id);
          $query = $this-&gt;db-&gt;get();
  
          if($query-&gt;num_rows()==1)
          {
              return $query-&gt;row();
          }
          else
          {
              //Get empty base parent object, as $employee_id is NOT an employee
              $grade_obj=new stdClass();
  
              //Get all the fields from items table
              $fields = $this-&gt;db-&gt;list_fields('grade_history');
  
              foreach ($fields as $field)
              {
                  $grade_obj-&gt;$field='';
              }
  
              return $grade_obj;
          }
      }
  
          /**
       * Inserts or updates configuration data
           *
       */
  
      function save_grade(&amp;$data, $employee_id=false)
      {
          if (!$employee_id)
          {
              if($this-&gt;db-&gt;insert('grade_history', $data))
              {
                  $data['id']=$this-&gt;db-&gt;insert_id();
                  return true;
              }
              return false;
          }
  
          $this-&gt;db-&gt;where('id', $employee_id);
          return $this-&gt;db-&gt;update('grade_history', $data);
      }
  
          // ------------------------ End of save_salary_cinfig function -----------------------------
  
  
          /*
           * Basic pay salary calculation
           */
          function basic_pay($employee_id)
          {
              // Get grade information from grade_history table
              // Get Particular person grade ifnormation by employ_id
              $grade_info = $this-&gt;get_grade_info($employee_id);
  
              $salary_grade           = $grade_info-&gt;salary_grade;
              $no_of_increment        = $grade_info-&gt;number_of_increment;
  
              // Get Grade rules information about particular grade by passing $salary_grade number
  
              $grade_rules            = $this-&gt;grade_rules_info($salary_grade);
  
              $basic_amount           = $grade_rules-&gt;basic_amount;
              $increment              = $grade_rules-&gt;increment;
              $max_no_of_increment    = $grade_rules-&gt;number_of_increment;
              $max_amount             = $grade_rules-&gt;max_amount;
  
              return $basic_pay = $basic_amount + $increment*$no_of_increment;
  
  
          }
  }
  ?&gt;
  
  controller
  
  &lt;?php
  require_once ("secure_area.php");
  class Salaries extends Secure_area
  {
      function __construct()
      {
          parent::__construct('salaries');
      }
  
      function index()
      {
          $data['controller_name']=strtolower($this-&gt;uri-&gt;segment(1));
          $data['form_width']=$this-&gt;get_form_width();
          $data['manage_table']=get_profile_manage_table($this-&gt;Profile-&gt;get_all(),$this);
          $this-&gt;load-&gt;view('salaries/manage',$data);
      }
  
      /*
      Returns profile table data rows. This will be called with AJAX.
      */
      function search()
      {
          $search=$this-&gt;input-&gt;post('search');
          $data_rows=get_profile_manage_table_data_rows($this-&gt;Profile-&gt;search($search),$this);
          echo $data_rows;
      }
  
      /*
      Gives search suggestions based on what is being searched for
      */
      function suggest()
      {
          $suggestions = $this-&gt;Profile-&gt;get_search_suggestions($this-&gt;input-&gt;post('q'),$this-&gt;input-&gt;post('limit'));
          echo implode("\n",$suggestions);
      }
  
      /*
      Loads the profile form
      */
      function view($employee_id=-1)
      {
          //$data['salary_summary_info']  =$this-&gt;Salary-&gt;get_info($salary_id);
          //$data['salary_deductions_summary_info'] =$this-&gt;Salary-&gt;get_deductions_info($salary_id);
  
                  $employee_id = array('' =&gt; '-- Select Employee ID --');
                  foreach($this-&gt;Profile-&gt;get_employee_id()-&gt;result_array() as $row)
          {
              $employee_id[$row['employee_id']]= $row['employee_id'];
          }
                  $data['employee_id'] = $employee_id;
                 // $data['selected_employee_id'] = $this-&gt;Profile-&gt;get_info($employee_id)-&gt;employee_id;
  
                  $data['basic_pay'] = $this-&gt;Salary-&gt;basic_pay($employee_id);
  
          $this-&gt;load-&gt;view("salaries/salary_summary_form", $data);
      }
          //--------------------------------------End view function-----------------------------------
  
      /*
      Loads the profile form
      */
      function grade_view($employee_id=-1)
      {
          $data['salary_grade_info']  = $this-&gt;Salary-&gt;get_grade_info($employee_id);
  
                  $data['basic_pay'] = $this-&gt;Salary-&gt;basic_pay($employee_id);
  
          $this-&gt;load-&gt;view("salaries/grade_view", $data);
      }
          //--------------------------------------End view function-----------------------------------
  
  
      /*
      Inserts/updates a profile
      */
      function save_salary_grade($id=-1)
      {
          $grade_data = array(
  
                      'eid'                   =&gt;$this-&gt;input-&gt;post('employee_id'),
                      'salary_grade'          =&gt;$this-&gt;input-&gt;post('salary_grade'),
                      'number_of_increment'   =&gt;$this-&gt;input-&gt;post('number_of_increment'),
                      'comments'              =&gt;$this-&gt;input-&gt;post('comments'),
                      'date'                  =&gt;date('Y-m-d H:i:s')
  
          );
  
          if($this-&gt;Salary-&gt;save_grade($grade_data, $id))
  
          {   //New profile
              if($id==-1)
              {
                  echo json_encode(array('success'=&gt;true,'message'=&gt;$this-&gt;lang-&gt;line('profiles_successful_adding').' '.
                  $grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=&gt;$grade_data['eid']));
              }
              else //previous profile
              {
                  echo json_encode(array('success'=&gt;true,'message'=&gt;$this-&gt;lang-&gt;line('profiles_successful_updating').' '.
                  $grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=&gt;$grade_data['eid']));
              }
          }
          else//failure
          {   
              echo json_encode(array('success'=&gt;false,'message'=&gt;$this-&gt;lang-&gt;line('profiles_error_adding_updating').' '.
              $grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=&gt;$grade_data['id']));
          }
      }
  
      /*
      This deletes profiles from the profiles table
      */
      function delete()
      {
          $profiles_to_delete=$this-&gt;input-&gt;post('ids');
  
          if($this-&gt;Profile-&gt;delete_list($profiles_to_delete))
          {
              echo json_encode(array('success'=&gt;true,'message'=&gt;$this-&gt;lang-&gt;line('profiles_successful_deleted').' '.
              count($profiles_to_delete).' '.$this-&gt;lang-&gt;line('profiles_one_or_multiple')));
          }
          else
          {
              echo json_encode(array('success'=&gt;false,'message'=&gt;$this-&gt;lang-&gt;line('profiles_cannot_be_deleted')));
          }
      }
  
      /*
      get the width for the add/edit form
      */
      function get_form_width()
      {           
          return 900;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>and view</p>
  
  <pre><code>&lt;?php
  echo form_open('salaries/save/'.$employee_id, array('id'=&gt;'salary_summary_form'));
  
  //echo form_open('salaries/save/', array('id'=&gt;'salary_summary_form'));
  ?&gt;
  &lt;div id="required_fields_message"&gt;&lt;?php echo $this-&gt;lang-&gt;line('common_fields_required_message'); ?&gt;&lt;/div&gt;
  &lt;ul id="error_message_box"&gt;&lt;/ul&gt;
  &lt;fieldset id="salary_allowance_info"&gt;
  &lt;legend&gt;&lt;?php echo $this-&gt;lang-&gt;line("salaries_allowance_info"); ?&gt;&lt;/legend&gt;
  
      &lt;div class="field_row clearfix"&gt;
      &lt;?php echo form_label($this-&gt;lang-&gt;line('salaries_employee_id').':', 'employee_id', array('class'=&gt;'required')); ?&gt;
              &lt;div class='form_field'&gt;
                  &lt;?php  echo form_dropdown('employee_id', $employee_id);?&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="field_row clearfix"&gt;
      &lt;?php echo form_label($this-&gt;lang-&gt;line('salaries_allowance_basic_salary').':', 'basic_salary', array('class'=&gt;'required')); ?&gt;
              &lt;div class='form_field'&gt;
              &lt;?php echo form_input(array(
                      'name'=&gt;'basic_salary',
                      'id'=&gt;'basic_salary',
                      'value'=&gt;$basic_pay
                      ));
              ?&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="field_row clearfix"&gt;
      &lt;?php echo form_label($this-&gt;lang-&gt;line('salaries_allowance_house_rent').':', 'house_rent',array('class'=&gt;'required')); ?&gt;
              &lt;div class='form_field'&gt;
              &lt;?php echo form_input(array(
                      'name'=&gt;'house_rent',
                      'id'=&gt;'house_rent',
  //                    'value'=&gt;$salary_summary_info-&gt;house_rent
                      ));
              ?&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  
  
  
  &lt;?php
  echo form_submit(array(
      'name'=&gt;'submit',
      'id'=&gt;'submit',
      'value'=&gt;$this-&gt;lang-&gt;line('common_submit'),
      'class'=&gt;'submit_button float_right')
  );
  
  ?&gt;
  &lt;/fieldset&gt;
  &lt;?php
  echo form_close();
  ?&gt;
  </code></pre>
  
  <p>pls help me if any one </p>