title: How to solve Message: Trying to get property of non-object error in Codeigniter?
body: <p>I'm very fresher in CodeIgniter and practicing. I'm now developing a simple Codeigniter application just for practicing. I've Banks and its branches in the database. I just want to show branches with its bank name. Branches are showing but in the controller while getting banks, this error is showing. I tried these in SO <a href="https://stackoverflow.com/search?q=Trying%20to%20get%20property%20of%20non-object%20codeigniter">links</a>, but nothing found works.</p>
  
  <pre><code>"A PHP Error was encountered
  
  Severity: Notice
  
  Message: Trying to get property of non-object"
  
  in Line Number: 85 and 91
  </code></pre>
  
  <p><strong>This is my controller</strong></p>
  
  <pre><code>function ShowBranchList() {
  
              $branch_list = $this-&gt;FD_Model-&gt;get_all_branches();
              $get_bank =   $this-&gt;FD_Model-&gt;get_bank_by_branch($branch_list-&gt;bankid); //This is Line Number 85
              if($branch_list ){
              $data = array(
                  'pagetitle' =&gt; 'Branch List View',
                  'branch_list_data' =&gt; $branch_list,
                  'br_bank' =&gt; $get_bank['bank_name'],//This is Line Number 93
              );
  
          }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>/*function for getting all branches*/
  
  function get_all_branches() {
      $this-&gt;db-&gt;order_by( $this-&gt;brid, $this-&gt;order );
      return $this-&gt;db-&gt;get( $this-&gt;brtable )-&gt;result();
  }
  
  
  /*function for getting banks by branches*/
  
  function get_bank_by_branch( $id ) {
          $this-&gt;db-&gt;where( $this-&gt;bid, $id);
          return $this-&gt;db-&gt;get( $this-&gt;banktable )-&gt;row();
      }
  </code></pre>
  
  <p>And finally, this is my <strong>View</strong></p>
  
  <pre><code> foreach ($branch_list_data as $branch_list) 
          { 
            &lt;?php echo $branch_list-&gt;brname ?&gt;
            &lt;?php echo $br_bank; ?&gt;
          }
  </code></pre>
  
  <p>Anyone know the issue?</p>
  
  <p><strong>Update</strong></p>
  
  <p>When I'm tring to view the query </p>
  
  <pre><code>echo $this-&gt;db-&gt;last_query();
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <blockquote>
    <p>SELECT * FROM <code>tbl_bankmaster</code> WHERE <code>bid</code> IS NULL </p>
  </blockquote>
  
  <p>The value <code>$branch_list-&gt;bankid</code> is <code>null</code>.When I'm hardcoding some values the view page is showing without any error.</p>