title: undefined variable and property of non-object in codeigniter
body: <p>I'm getting these two error messages for my 3 variables:</p>
  
  <p>message 1) Undefined variable: rows
  message 2) Trying to get property of non-object</p>
  
  <p>EDIT: (finally found the edit button), so the 3 variables are:</p>
  
  <pre><code>        $anatomic_code = $rows-&gt;NerveCode;
          $ProxAccess = $rows-&gt;ProxAccess;
          $DistAccess = $rows-&gt;DistAccess;
  </code></pre>
  
  <p>Which can be found in my view, it is the above 3 lines that are giving me the two errors. </p>
  
  <p>I have not included the model as I don't think the problem is there, and more so because its quite some code due to the developers before me has used lots of different tables storing the data in... however I'm ready to post it if needed. </p>
  
  <p>Controller -></p>
  
  <pre><code>function se_enkel_test()
      {
      $this-&gt;freakauth_light-&gt;check('submitter');
      $tech_num = $this-&gt;uri-&gt;segment(6);
      $this-&gt;load-&gt;model('view_single_test','',true);
      $data['query'] = $this-&gt;view_single_test-&gt;query();
      $data['query_tech_type'] =  $this-&gt;view_single_test-&gt;query_tech_type();
      $data['query_parameters'] =  $this-&gt;view_single_test-&gt;query_parameters();
      $data['query_tech_name'] =  $this-&gt;view_single_test-&gt;query_tech_name();
      $data['query_test'] =  $this-&gt;view_single_test-&gt;query_test();
      $data['query_temperat'] =  $this-&gt;view_single_test-&gt;query_temperat();
      $data['query_semiq'] =  $this-&gt;view_single_test-&gt;query_semiq();
      $data['query_conclusion'] =  $this-&gt;view_single_test-&gt;query_conclusion();
      $data['query_side'] =  $this-&gt;view_single_test-&gt;query_side();
  
      $this-&gt;load-&gt;model('mysql_create','',true);
      $data['dropdown_conclusion_diagnosis'] = $this-&gt;mysql_create-&gt;get_dropdown_conclusion($tech_num);
      $data['dropdown_conclusion_duration'] = $this-&gt;mysql_create-&gt;get_dropdown_duration_diagnosis();
      $data['dropdown_conclusion_severity'] = $this-&gt;mysql_create-&gt;get_dropdown_severity_diagnosis();
  
      $this-&gt;load-&gt;view('auh/se_enkel_test', $data);
      }
  </code></pre>
  
  <p>View -> </p>
  
  <pre><code>elseif ($struct_id == "3") {
  
              foreach($query-&gt;result() as $rows):
              if ($rows-&gt;NerveCode &gt; 10000 ){
                  echo "&lt;h3&gt;N." . $rows-&gt;NerveName . ") (" . $side-&gt;SideText.")&lt;/h3&gt;";        
  
              }
              else {
                  echo "&lt;h3&gt;N." . $rows-&gt;NerveName . " (" . $rows-&gt;ProxName . " - ";
                      if ($rows-&gt;Code &lt; 3000) {
                          echo "m.";
                          }
                      echo $rows-&gt;DistName . ") ("  . $side-&gt;SideText.")&lt;/h3&gt;";
              }
              endforeach;
              $anatomic_code = $rows-&gt;NerveCode;
              $ProxAccess = $rows-&gt;ProxAccess;
              $DistAccess = $rows-&gt;DistAccess;
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kMmlf.png" rel="nofollow noreferrer">This is how my page looks now facing the errors, one should be aware there several errors above this page, as stated earlier in the post. but the same two errors for all 3 variables. </a></p>
  
  <p><a href="https://i.stack.imgur.com/6Vl92.png" rel="nofollow noreferrer">This is how the original page used to look. </a></p>
  
  <p>From the two screenshots you can see that the problem on my page is I'm not getting the "length of segment" value.. and the muscle name: 
  "N.peroneus (ankle - m.extensor digitorum brevis) (sin.)" </p>
  
  <p>The model with function "query" -></p>
  
  <pre><code>function query()
  {
      $exam = $this-&gt;uri-&gt;segment(3);    
      $type_id = $this-&gt;uri-&gt;segment(4);
      $struct_id = $this-&gt;uri-&gt;segment(5);    
      $technique_id = $this-&gt;uri-&gt;segment(6);
      $test_id = $this-&gt;uri-&gt;segment(7);
          switch($type_id)
          {
              case 1:
                  $query_input = "SELECT EMUSCLE.*, NERVMUSCACCP.NAME AS MuscleName, NERVMUSCACCP.ShortName AS ShortMuscleName FROM EMUSCLE,NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND EMUSCLE.MuscleCode = NERVMUSCACCP.Code;";
                  break;
              case 2:
                  $query_input = "SELECT ENERVE.*, NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM ENERVE,NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND ENERVE.NerveCode = NERVMUSCACCP.Code;";
                  break;
              case 3:
                  $query_input = "SELECT NewTable2.*, prox2.Code, prox2.Name AS DistName, prox2.ShortAccPName AS ShortDistName FROM (SELECT NewTable1.*, prox.Name AS ProxName, prox.ShortAccPName AS ShortProxName FROM (SELECT es.*,  NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM ESEGMENT es, NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND es.NerveCode = NERVMUSCACCP.Code) AS NewTable1 LEFT OUTER JOIN PROXDISTINFO prox ON NewTable1.ProxAccess = prox.Code) AS NewTable2 LEFT OUTER JOIN PROXDISTINFO prox2 ON NewTable2.DistAccess = prox2.Code;";
                  break;
              case 4:
                  $query_input = "SELECT NewTable1.*, NERVMUSCACCP.NAME AS MuscleName, NERVMUSCACCP.ShortName AS ShortMuscleName FROM (SELECT EJNCTION.*, NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM EJNCTION LEFT OUTER JOIN NERVMUSCACCP ON EJNCTION.NerveCode = NERVMUSCACCP.Code WHERE EJNCTION.Exam = ".$exam." AND Struct = ".$struct_id.") AS NewTable1 LEFT OUTER JOIN NERVMUSCACCP ON NewTable1.MuscleCode = NERVMUSCACCP.Code";
                  break;
          }    
      $query = $this-&gt;db-&gt;query($query_input);
  
      return $query;
  }
  </code></pre>