title: codeigniter - Uninitialized string offset: 0 and Illegal string offset
body: <p>I loop in a loop and there are errors.
  I tried this before but now it doesn't work.</p>
  
  <p>My errors are:</p>
  
  <hr>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Notice</p>
    
    <p>Message: Uninitialized string offset: 0</p>
    
    <p>Filename: views/audit_trail_view.php</p>
    
    <p>Line Number: 36</p>
    
    <p>Backtrace:</p>
    
    <p>File:
    C:\xampp\htdocs\cemo-marikina\application\views\audit_trail_view.php
    Line: 36 Function: _error_handler</p>
    
    <p>File:
    C:\xampp\htdocs\cemo-marikina\application\controllers\Employee.php
    Line: 2819 Function: view</p>
    
    <p>File: C:\xampp\htdocs\cemo-marikina\index.php Line: 292 Function:
    require_once</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Warning</p>
    
    <p>Message: Illegal string offset 'user_id'</p>
    
    <p>Filename: views/audit_trail_view.php</p>
    
    <p>Line Number: 36</p>
    
    <p>Backtrace:</p>
    
    <p>File:
    C:\xampp\htdocs\cemo-marikina\application\views\audit_trail_view.php
    Line: 36 Function: _error_handler</p>
    
    <p>File:
    C:\xampp\htdocs\cemo-marikina\application\controllers\Employee.php
    Line: 2819 Function: view</p>
    
    <p>File: C:\xampp\htdocs\cemo-marikina\index.php Line: 292 Function:
    require_once</p>
  </blockquote>
  
  <p>Views: audit_trail_view.php</p>
  
  <pre><code>&lt;?php 
      $first_name='';
      $last_name='';
      $middle_name='';
      $separator="";
      $user_id="";
  
      ?&gt;
          &lt;table border ="1" width="75%" &gt;
              &lt;tr&gt;
                  &lt;td&gt;User&lt;/td&gt;
                  &lt;td&gt;Action&lt;/td&gt;
                  &lt;td&gt;Date&lt;/td&gt;
              &lt;/tr&gt;
      &lt;?php
      foreach($view as $view){
  
          $audit_id= $view['audit_id'];
          $audit_user_id= $view['audit_user_id'];
          $audit_record= $view['audit_record'];
          $audit_new_record= $view['audit_new_record'];
  
          $audit_date= $view['audit_date'];
          $timestamp=strtotime($view['audit_date']);
  
  
          $year=date('Y', $timestamp);
          $month=date('M', $timestamp);
          $day=date('d', $timestamp);
          $hour=date('h', $timestamp);
          $minute=date('i', $timestamp);
          $ap=date('a', $timestamp);
          foreach($users as $users){
              $id =$users['user_id'];
              if($id==$audit_id){
                  $first_name=$users['fname'];
                  $last_name=$users['lname'];
                  $middle_name=$users['mname'];
              }
              else{
                  $first_name='';
                  $last_name='';
                  $middle_name='';
              }
  
          }
      ?&gt;  
  
  
          &lt;tr&gt;
  
              &lt;td&gt;&lt;?php echo $last_name." ".$first_name.", ".$middle_name;?&gt; &lt;/td&gt;
              &lt;td&gt;&lt;?php echo$audit_record.$separator.$audit_new_record;?&gt; &lt;/td&gt;
              &lt;td&gt;&lt;?php echo$month." ".$day.", ".$year." ".$hour.":".$minute." ".$ap;?&gt; &lt;/td&gt;
          &lt;/tr&gt;   
  
      &lt;?php   
      }
  
  
  
  
  
  ?&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>Controller:Employee.php </p>
  
  <pre><code>public function audit_trail_view(){
      $data['view']=$this-&gt;emp_model-&gt;audit_trail_view();
      $data['users']=$this-&gt;emp_model-&gt;audit_trail_users();
      $this-&gt;load-&gt;view("audit_trail_view.php",$data);
  }
  </code></pre>
  
  <p>Model: Emp_model.php</p>
  
  <pre><code>/* AUDIT TRAIL VIEW START*/
      function audit_trail_view(){
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('audit_table');
  
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result_array();
      }
  
      function audit_trail_users(){
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('users');
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result_array();
      }
  /* AUDIT TRAIL VIEW END*/
  
  /* AUDIT TRAIL START */
      function audit_trail(){
          $data=array(
              'audit_user_id'=&gt;$this-&gt;input-&gt;post('audit_user_id'),
              'audit_record'=&gt;$this-&gt;input-&gt;post('audit_record'),
              'audit_new_record'=&gt;$this-&gt;input-&gt;post('audit_new_record'),
          );
          $this-&gt;db-&gt;insert('audit_table',$data);
      }
  /* AUDIT TRAIL END */   
  </code></pre>