title: Codeigniter - How to passing multiple data from multiple table to a single View?
body: <p>I've table in database.</p>
  
  <p><code>tbl_parameter</code> column:</p>
  
  <pre><code>parameter_ID | parameter_name | parameter_unit | parameter_method
  ------------ | -------------- | -------------- | ----------------
  3001         | Salt           | %              | Titrimetri
  3002         | pH             | -              | pH meter
  3003         | Visco          | poise          | Viscometer
  </code></pre>
  
  <p>Next is <code>tbl_coa</code> to store the COA page input. <code>parameter_ID</code> come from multi select input, so it stored comma separated.</p>
  
  <pre><code>coa_ID | coa_number  | coa_year | product_ID | customer_ID | parameter_ID
  ------ | ----------- | -------- | ---------- | ----------- | ------------
  4001   | 001/01/2017 | 2017     | 10001      | 2111        | 3001,3002,3003
  </code></pre>
  
  <p>Next I'm working the View page that display COA details, the view saved as <code>view_coa.php</code>. The code as below. I'm defining <code>{PRE}</code> to replace <code>tbl_</code>.</p>
  
  <p>Model <code>Coa_model.php</code>:</p>
  
  <pre><code>function get_coa_detail($coa_ID){
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('{PRE}coa');
      $this-&gt;db-&gt;join('{PRE}product', '{PRE}product.product_ID  = {PRE}coa.product_ID', 'LEFT');
      $this-&gt;db-&gt;join('{PRE}customer', '{PRE}customer.customer_ID  = {PRE}coa.customer_ID', 'LEFT');
      $this-&gt;db-&gt;join('{PRE}parameter', '{PRE}parameter.parameter_ID  = {PRE}coa.parameter_ID', 'LEFT');
      $this-&gt;db-&gt;where('{PRE}coa.coa_ID', $coa_ID);
      $query = $this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows() &gt; 0){
          $data = $query-&gt;row();
          $query-&gt;free_result();
      }
      else{
          $data = NULL;
      }
  
      return $data;
  }
  </code></pre>
  
  <p>Controller <code>Coa.php</code>:</p>
  
  <pre><code>public function view_coa($coa_ID=0){
      if($coa_ID != 0 &amp;&amp; !empty($coa_ID)){
          $data = array(
                  'record' =&gt; $this-&gt;Coa_model-&gt;get_coa_detail($coa_ID)
              );
          //print_r($data);
          $this-&gt;site-&gt;view('view_coa', $data);
      }
      else{
          redirect(set_url('coa/data_table/'.date('Y')));
      }
  }
  </code></pre>
  
  <p>The problem is, when I want to show the parameter details (that stored as comma separated <code>parameter_ID</code>) it just shown the datas from first <code>parameter_ID</code> only. In the example above, it just shown the detail for <code>parameter_ID = 3001</code>. I want to display the datas (<code>parameter_name</code>, <code>parameter_unit</code>, <code>parameter_method</code>) from all <code>parameter_ID</code> (3001,3002, and 3003).</p>
  
  <p>The <code>print_r</code> data result:</p>
  
  <pre><code>Array ( [record] =&gt; stdClass Object ( [coa_ID] =&gt; 4001 [coa_number] =&gt; 001/01/2017 [coa_year] =&gt; 2017 [product_ID] =&gt; 10001 [product_type] =&gt; Sweet Soy [product_name] =&gt; Product A [Salt] =&gt; 5.5 [pH] =&gt; 4.4 [Visco] =&gt; 12.5 [customer_ID] =&gt; 2111 [customer_name] =&gt; Company 1 [parameter_ID] =&gt; 3001 [parameter_name] =&gt; Salt [parameter_unit] =&gt; % [parameter_method] =&gt; Titrimetri ) )
  </code></pre>
  
  <p>My question is, how to display all parameters details for <code>[parameter_ID] =&gt; 3002</code> and <code>[parameter_ID] =&gt; 3003</code>?</p>
  
  <p>Current view <code>view_coa</code> to display data from database:</p>
  
  <pre><code>  &lt;!-- COA title and number row --&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-xs-12 coa-title-number"&gt;
        &lt;h3&gt;Certificate of Analysis&lt;/h3&gt;
        &lt;p&gt;NO. &lt;?php echo $record-&gt;no_coa;?&gt;&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;!-- COA detail row --&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-xs-1"&gt;
      &lt;/div&gt;
      &lt;div class="col-xs-11"&gt;
        &lt;table class="table-coa-detail"&gt;
          &lt;tr class="text-nowrap"&gt;
            &lt;th&gt;Product Name&lt;/th&gt;
            &lt;td&gt;&lt;strong&gt;: &lt;?php echo $record-&gt;product_name;?&gt;&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="text-nowrap"&gt;
            &lt;th&gt;Customer Name&lt;/th&gt;
            &lt;td&gt;&lt;strong&gt;: &lt;?php 
              if($record-&gt;customer_ID == "0" || $record-&gt;customer_ID == NULL){
                echo "-";
              }
              else{
                echo $record-&gt;customer_name;
              }
            ?&gt;&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="text-nowrap"&gt;
            &lt;th&gt;Analysis Results&lt;/th&gt;
            &lt;td&gt;:&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;!-- COA results row --&gt;
    &lt;div style="padding-right: 50px;" class="row"&gt;
      &lt;div class="col-xs-1"&gt;                      
      &lt;/div&gt;
      &lt;div class="col-xs-11"&gt;
        &lt;table class="table-results"&gt;
          &lt;thead&gt;
            &lt;tr&gt;
            &lt;th&gt;No&lt;/th&gt;
            &lt;th&gt;Parameter&lt;/th&gt;
            &lt;th&gt;Unit&lt;/th&gt;
            &lt;th&gt;Results&lt;/th&gt;
            &lt;th&gt;Method&lt;/th&gt;
            &lt;th&gt;Conclusion&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody class="text-nowrap"&gt;
            &lt;tr&gt;
            &lt;td style="text-align: center;"&gt;1&lt;/td&gt;
            &lt;td&gt;&lt;strong&gt;Analytical&lt;/strong&gt;
              &lt;?php 
              if($record-&gt;product_type == "Sweet Soy"){
                echo "&lt;p&gt;pH&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_name."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;Visco&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_name."&lt;/p&gt;"; from [parameter_ID] =&gt; 3003
                echo "&lt;p&gt;Salt&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_name."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              else{
                echo "&lt;p&gt;pH&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_name."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;Salt&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_name."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              ?&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center;"&gt;&amp;nbsp;
              &lt;?php 
              if($record-&gt;product_type == "Sweet Soy"){
                echo "&lt;p&gt;-&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_unit."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;poise&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_unit."&lt;/p&gt;"; from [parameter_ID] =&gt; 3003
                echo "&lt;p&gt;%&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_unit."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              else{
                echo "&lt;p&gt;-&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_unit."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;%&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_unit."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              ?&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center;"&gt;&amp;nbsp;
              &lt;?php 
              if($record-&gt;product_type == "Sweet Soy"){
                echo "&lt;p&gt;".$record-&gt;pH."&lt;/p&gt;";
                echo "&lt;p&gt;".$record-&gt;Visco."&lt;/p&gt;";
                echo "&lt;p&gt;".$record-&gt;Salt."&lt;/p&gt;";
              }
              else{
                echo "&lt;p&gt;".$record-&gt;pH."&lt;/p&gt;";
                echo "&lt;p&gt;".$record-&gt;Salt."&lt;/p&gt;";
              }
              ?&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center;"&gt;&amp;nbsp;
              &lt;?php 
              if($record-&gt;product_type == "Sweet Soy"){
                echo "&lt;p&gt;pH meter&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_method."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;Viscometer&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_method."&lt;/p&gt;"; from [parameter_ID] =&gt; 3003
                echo "&lt;p&gt;Titrimetri&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_method."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              else{
                echo "&lt;p&gt;pH meter&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_method."&lt;/p&gt;"; from [parameter_ID] =&gt; 3002
                echo "&lt;p&gt;Titrimetri&lt;/p&gt;"; // it should "&lt;p&gt;".$record-&gt;parameter_method."&lt;/p&gt;"; from [parameter_ID] =&gt; 3001
              }
              ?&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center;"&gt;&amp;nbsp;
              &lt;p&gt;OK&lt;/p&gt;
              &lt;p&gt;OK&lt;/p&gt;
              &lt;p&gt;OK&lt;/p&gt;
            &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>