title: Retrieve specific column from database and display on screen using CodeIgniter
body: <p>I have a database table called input_types with a various input types:</p>
  
  <pre><code>[id]  [input_type_Name]
   1    text
   2    radio
   3    checkbox
   4    select
   ...  ...
  </code></pre>
  
  <p>I want to retrieve the names from the table and put them in an array so that I can then use form_dropdown to show them to the user in a dropdown.</p>
  
  <p>The problem with how I'm doing it now is that I create optiongroups. </p>
  
  <p>How I do it now:</p>
  
  <h1>Model</h1>
  
  <pre><code>function get_inputTypes() {
      $this-&gt;db-&gt;select('input_type_name');
      $query = $this-&gt;db-&gt;get('input_types');
  
      if($query-&gt;num_rows() &gt; 0) {
          return $query-&gt;result_array();
      }
  
      else {
          return false;
      }
  }
  </code></pre>
  
  <h1>Controller</h1>
  
  <pre><code>$results = $this-&gt;survey_model-&gt;get_inputTypes();
  $data['inputTypes'] = $results;
  </code></pre>
  
  <h1>View</h1>
  
  <pre><code>&lt;label for="inputType"&gt;Input type:&lt;/label&gt;
  &lt;?php echo form_dropdown('inputType', $inputTypes); ?&gt;
  </code></pre>
  
  <p>This however doesn't create the desired effect. My dropdown gets populated, but because I have a multidimensional array the dropdown has optgroups.</p>
  
  <p>I just want to have my selected data in a simple array. Why is this so freaking hard in CodeIgniter and php in general.</p>
  
  <p>C# is much easier :/</p>
  
  <h1>Solution</h1>
  
  <p>The solution is very simple, use a foreach to loop through the multidimensional array in the model:</p>
  
  <pre><code>foreach($query-&gt;result() as $input_type) {
      $data[] = $input_type-&gt;input_type_name;
  }
  
  return $data;
  </code></pre>