title: How can I extract multiple fieldnames/column values - Codeigniter?
body: <p>Suppose I have this native query on my model:</p>
  
  <pre><code>public function print_query($id){
  
  $sql = "Select Field1,Field2,Field3.. FROM Table WHERE id = '".$id."' ";
  
      if($this-&gt;db-&gt;query($sql, array($id))-&gt;num_rows() &gt; 0)
      {
      return $this-&gt;db-&gt;query($sql, array($id))-&gt;result();
      }
  }
  </code></pre>
  
  <p>And this on my Controller:</p>
  
  <pre><code>public function emp_preview(){
  
  $EmpID =  $this-&gt;input-&gt;post('txt_id');
  $data['p_det'] = $this-&gt;db_sal_details-&gt;print_query($EmpID);
  $this-&gt;load-&gt;view('employee/preview',$data,TRUE);
  
  }
  </code></pre>
  
  <p>And in my View: I wanted to display the values of Field1,Field2,Field3,and so on.,
  I used this code to display them;</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;                            
  &lt;?php if($p_det):?&gt;
  &lt;?php foreach($p_det as $det):?&gt;
  &lt;th&gt;&lt;?php echo $det-&gt;Field1;?&gt;&lt;/th&gt;
  &lt;th&gt;&lt;?php echo $det-&gt;Field2;?&gt;&lt;/th&gt;
  &lt;th&gt;&lt;?php echo $det-&gt;Field2;?&gt;&lt;/th&gt;
  ...
  &lt;?php endforeach;?&gt;
  &lt;?php endif;?&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This is all work fine and display the field and its values. But what if i have more than just 3 fields (50 fields e.g) and I want to dynamically populate the TH with out typing each Fields. How can i do this.,?</p>
  
  <p>I know it's very simple for you experts ,.but I'm just a beginner here.. please bear with me and help me with this one., Thanks in Advance for any replies..                             </p>