title: Severity: Notice Message: Trying to get property of non-object codeigniter
body: <p><strong>My Controller:</strong></p>
  
  <pre><code>function generateallmonthreport()
      {
          $month = $this-&gt;input-&gt;post('month');
          $year = $this-&gt;input-&gt;post('year');
          $familyid = $this-&gt;session-&gt;userdata('family_id');
  
          $fulldata['dates'] = $this-&gt;Itemreport_model-&gt;getreportallmonth($month,$year);
          $fulldata['members1'] = $this-&gt;Itemreport_model-&gt;getindependentmembers($familyid);
          $fulldata['members2'] = $this-&gt;Itemreport_model-&gt;getindependentmembers($familyid);
          $fulldata['members3'] = $this-&gt;Itemreport_model-&gt;getindependentmembers($familyid);
          $fulldata['members4'] = $this-&gt;Itemreport_model-&gt;getindependentmembers($familyid);
          $fulldata['members5'] = $this-&gt;Itemreport_model-&gt;getindependentmembers($familyid);
          $fulldata['year'] = $year;
          $fulldata['month'] = $month;
  
          $this-&gt;load-&gt;view('header');
          $this-&gt;load-&gt;view('itemreports/allmonthreportpage', $fulldata);
          $this-&gt;load-&gt;view('footer');
      }
  </code></pre>
  
  <p><strong>My Model:</strong></p>
  
  <pre><code>function getreportallmonth($month,$year)
  {
      $sql = "SELECT DISTINCT `item_date` FROM `items` WHERE MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year'";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  
  function getindependentmembers($familyid)
  {
      $sql = "SELECT * FROM `familymember` WHERE `family_id`='$familyid' AND `dependency`='1'";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  
  function getcountofexpensetype($memberid,$year,$month)
  {
      $sql = "SELECT COUNT(DISTINCT `item_expensetype`) AS spancount FROM `items` WHERE `item_purchaseby`='$memberid' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  
  function getexpensetype($memberidforexpensetype,$year,$month)
  {
      $sql = "SELECT DISTINCT `item_expensetype` as expensetype FROM `items` WHERE `item_purchaseby`='$memberidforexpensetype' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  
  function getallitems($thisdate)
  {
      $sql = "SELECT `item_name`,`item_price`,`item_purchasetype` FROM `items` WHERE `item_date`='$thisdate'";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  
  function getexpensetypefinal($memberidforexpensetypeprice,$year,$month)
  {
      $sql = "SELECT DISTINCT `item_expensetype` as expensetype FROM `items` WHERE `item_purchaseby`='$memberidforexpensetypeprice' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
      $query = $this-&gt;db-&gt;query($sql);
      return $query-&gt;result();
  }
  </code></pre>
  
  <p><strong>My View:</strong></p>
  
  <pre><code>&lt;table border="2" id="tab" style="width:100%" class="text-center m-auto table table-bordered table-hover"&gt;
  
                      &lt;tr&gt;
                          &lt;td rowspan="2"&gt;Date&lt;/td&gt;
                          &lt;td rowspan="2"&gt;Items&lt;/td&gt;
  
                          &lt;!-- php code for getting all individual member header for individual expense types --&gt;
  
                          &lt;?php foreach ($members1 as $members1) { ?&gt;
                                  &lt;?php
                                      $this-&gt;load-&gt;model('Itemreport_model');
                                      $memberid = $members1-&gt;member_id;
                                      $countforcolspan = $this-&gt;Itemreport_model-&gt;getcountofexpensetype($memberid,$year,$month);
                                  ?&gt;
  
                                  &lt;td colspan="&lt;?php foreach ($countforcolspan as $countforcolspan) { echo $countforcolspan-&gt;spancount+1; } ?&gt;"&gt;
                                      &lt;?php echo $members1-&gt;membername."'s Individual Expenses"; ?&gt;
                                  &lt;/td&gt;
  
                          &lt;?php } ?&gt;
  
                          &lt;td rowspan="2"&gt;Total Expense On Common&lt;/td&gt;
  
                          &lt;!-- php code for getting all individual member header --&gt;
                          &lt;?php foreach ($members2 as $members2) { ?&gt;
                              &lt;td rowspan="2"&gt;&lt;?php echo $members2-&gt;membername."'s Total Expense (Individual + Common)"; ?&gt;&lt;/td&gt;
                          &lt;?php } ?&gt;
  
                          &lt;td rowspan="2"&gt;Total Expense Of Family&lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;tr&gt;
                          &lt;?php
                              foreach ($members3 as $members3) {
                                  $memberidforexpensetype = $members3-&gt;member_id;
                                  $expensetype = $this-&gt;Itemreport_model-&gt;getexpensetype($memberidforexpensetype,$year,$month);
                                  foreach ($expensetype as $expensetype) { ?&gt;
                                      &lt;td&gt;&lt;?php echo $expensetype-&gt;expensetype; ?&gt;&lt;/td&gt;
                                  &lt;?php } ?&gt;
                                  &lt;td&gt;Total&lt;/td&gt;
                              &lt;?php }
                          ?&gt;
                      &lt;/tr&gt;
  
                      &lt;tbody id="tbodydata"&gt;
  
                          &lt;?php foreach ($dates as $dates) { ?&gt;
                              &lt;tr&gt;
  
                                  &lt;td&gt;&lt;?php $thisdate = $dates-&gt;item_date; echo $thisdate; ?&gt;&lt;/td&gt;
  
                                  &lt;td&gt;&lt;?php
                                      $allitems = $this-&gt;Itemreport_model-&gt;getallitems($thisdate);
                                      foreach ($allitems as $allitems) {
                                          echo $allitems-&gt;item_name; ?&gt; (&lt;?php echo $allitems-&gt;item_price; ?&gt;)
                                      &lt;?php }
                                  ?&gt;&lt;/td&gt;
  
                                  &lt;?php foreach ($members4 as $members4) {
                                      $memberidforexpensetypeprice = $members4-&gt;member_id;
                                      $countforcolspan = $this-&gt;Itemreport_model-&gt;getexpensetypefinal($memberidforexpensetypeprice,$year,$month);
                                   } ?&gt;
                              &lt;/tr&gt;
                          &lt;?php } ?&gt;
  
                      &lt;/tbody&gt;
  </code></pre>
  
  <p>The code seems to work fine but gives me the notice of Trying to get property of non-object</p>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>A PHP Error was encountered
    Severity: Notice
    Message: Trying to get property of non-object
    Filename: itemreports/allmonthreportpage.php Line Number: 68</p>
    
    <p>Backtrace:
    File: D:\wampserver\www\home\application\views\itemreports\allmonthreportpage.php
    Line: 68
    Function: _error_handler</p>
    
    <p>File: D:\wampserver\www\home\application\controllers\Itemreport.php
    Line: 91
    Function: view</p>
    
    <p>File: D:\wampserver\www\home\index.php
    Line: 315
    Function: require_once</p>
  </blockquote>
  
  <p>I cannot spot the impropper part of code.. Please Help..!!</p>