title: "PHP Error was Encountered" Error in codeigniter project
body: <p>I get the following errors while trying to view my create new user page.</p>
  
  <p>A PHP Error was encountered
  Severity: Notice
  Message: Undefined variable: list
  Filename: views/rtc.php
  Line Number: 33</p>
  
  <p>A PHP Error was encountered
  Severity: Notice
  Message: Trying to get property of non-object
  Filename: views/rtc.php
  Line Number: 33</p>
  
  <p>I get these errors while trying to run my create new user file, where I am trying to create a dynamic drop down list. Below is my 
  view>rtc.php</p>
  
  <pre><code>&lt;script type="text/javascript" src="js/common.js"&gt;&lt;/script&gt;
      &lt;div class="contentform"&gt;        
  
          &lt;fieldset style="width:55%;float:left;margin-left:5%;"&gt;
              &lt;legend &gt;New RTC&lt;/legend&gt;
  
          &lt;!--FORM STARTS HERE--&gt;
  
          &lt;form action="&lt;?= site_url('form/rtc_insert'); ?&gt;" method="post"&gt;   
  
              &lt;label &gt;RTC ID:&lt;span id="rtc_reg_id_re" style="font-size:12px;float:right;"&gt;&lt;/span&gt;&lt;/label&gt;
              &lt;input type="text" name="id" id="rtc_reg_id" placeholder="RTC ID" required/&gt;                 
              &lt;label &gt;Name:&lt;/label&gt;
              &lt;input type="text" name="name"  placeholder="Name" required/&gt;
                  &lt;label &gt;Country:&lt;/label&gt;
                     &lt;select name="country" &gt;
                         &lt;option&gt;Select Country&lt;/option&gt;
                          &lt;option value="Bangladesh"&gt;Bangladesh&lt;/option&gt;
                          &lt;option value="India"&gt;India&lt;/option&gt;
                          &lt;option value="Nepal"&gt;Nepal&lt;/option&gt;
                          &lt;option value="Bhutan"&gt;Bhutan&lt;/option&gt;
                          &lt;/select&gt;&lt;br/&gt;&lt;br/&gt;                                
              &lt;?php
              if($list-&gt;num_rows &gt; 0){
                  ?&gt;
                  &lt;label &gt;Dzongkhag:&lt;/label&gt;
                  &lt;select onchange="selectGeog(this.options[this.selectedIndex].value)"&gt;
                      &lt;option value="-1"&gt;Select Dzongkhag&lt;/option&gt;
              &lt;?php foreach($list-&gt;result() as $listElement){ ?&gt;
                      &lt;option value="&lt;?php echo $listElement-&gt;id?&gt;"&gt;&lt;?php echo $listElement-&gt;dz_name?&gt;&lt;/option&gt;
              &lt;?php
                      }
                  ?&gt; 
  
                   &lt;label &gt;Geog:&lt;/label&gt;
                  &lt;select id="geog_dropdown" onchange="selectVillage(this.options[this.selectedIndex].value)"&gt;
                      &lt;option value="-1"&gt;Select geog&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;span id="geog_loader"&gt;&lt;/span&gt;
  
                  &lt;label &gt;Village:&lt;/label&gt;
                  &lt;select id="village_dropdown"&gt;
                      &lt;option value="-1"&gt;Select village&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;span id="village_loader"&gt;&lt;/span&gt;
  
                  &lt;label &gt;Address:&lt;/label&gt;
                  &lt;textarea type="text" name="address" placeholder="Address" required/&gt;&lt;/textarea&gt;                       
                  &lt;input type="submit" value="Save" id="rtc_reg_submit" class="button"&gt;&lt;br/&gt;
               &lt;?php
              }else{
                  echo 'No Country Name Found';
              }
              ?&gt;
                  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my controller>form.php</p>
  
  <pre><code>    function rtc_insert()   
      {
  
          $session_user=$this-&gt;session-&gt;userdata('logged_in');
          if($session_user['ath']=='admin')
          {$msg = $this-&gt;drop_model-&gt;getDzongkhag();
              redirect('form/rtc/You Have Successfully Created '.$msg);
  
          }
          else
              {
              echo ' &lt;script type="text/javascript"&gt;
                          alert("Access Error....");
                          &lt;/script&gt;';
                  redirect('login/home');
              }
  
      }
  public function dropDown()
      {
          $this-&gt;load-&gt;model('drop_model');
          $result['list']=$this-&gt;model-&gt;getDzongkhag();
          $this-&gt;load-&gt;view('rtc',$result);
          }
  
      public function loadData()
      {
          $loadType=$_POST['loadType'];
          $loadId=$_POST['loadId'];
  
          $this-&gt;load-&gt;model('drop_modelmodel');
          $result=$this-&gt;model-&gt;getData($loadType,$loadId);
          $HTML="";
  
          if($result-&gt;num_rows() &gt; 0){
              foreach($result-&gt;result() as $list){
                  $HTML.="&lt;option value='".$list-&gt;id."'&gt;".$list-&gt;name."&lt;/option&gt;";
              }
          }
          echo $HTML;
      }
  </code></pre>
  
  <p>and the model>drop_model.php</p>
  
  <pre><code>    &lt;?php
  class drop_model extends CI_Model
  {
      function __construct()
      {
          parent::__construct();
      }
  
      function getDzongkhag(){
          $this-&gt;db-&gt;select('id,dz_name');
          $this-&gt;db-&gt;from('dzongkhag');
          $this-&gt;db-&gt;order_by('dz_name', 'asc'); 
          $query=$this-&gt;db-&gt;get();
          return $query; 
      }
  
      function getData($loadType,$loadId){
          if($loadType=="geog"){
              $fieldList='gid,g_name as name';
              $table='geog';
              $fieldName='dz_id';
              $orderByField='g_name';                     
          }else{
              $fieldList='vid,village_name as name';
              $table='village';
              $fieldName='geog_id';
              $orderByField='village_name';   
          }
  
          $this-&gt;db-&gt;select($fieldList);
          $this-&gt;db-&gt;from($table);
          $this-&gt;db-&gt;where($fieldName, $loadId);
          $this-&gt;db-&gt;order_by($orderByField, 'asc');
          $query=$this-&gt;db-&gt;get();
          return $query; 
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Everything was running fine, problem started after I added the codes for the dynamic drop down list in my form which I learned from a tutorial! Any help will be welcome. Thank you</p>