title: How to get data on database and display in "select" dropdown in view (Codeigniter)
body: <p>I am a newbie to CodeIgniter, I have created a simple app that will fetch data from database and then display it in a <code>&lt;SELECT&gt;</code> dropdown. I'm trying to get data from a specific field from database to my view. So far, I have tried the code below (not working):</p>
  
  <p>My model (datamodel.php),</p>
  
  <pre><code>function getbanklist() {
      $banklist = array();
      $this-&gt;db-&gt;select("id, bank");
      $this-&gt;db-&gt;from('bank');
      $query = $this-&gt;db-&gt;get();
  
      if ($query-&gt;num_rows &gt;= 1){
          foreach($query-&gt;result_array() as $row){
              $banklist[$row['id']]=$row['bank'];
          }
          return $banklist;
      }
  }
  </code></pre>
  
  <p>My controller (home.php),</p>
  
  <pre><code>function index(){
      $data['bankdata'] = $this-&gt;datamodel-&gt;getbanklist();
      $this-&gt;load-&gt;view('viewdata', $data);
  }
  </code></pre>
  
  <p>My view (viewdata.php),</p>
  
  <pre><code>&lt;tr&gt;
      &lt;th&gt;BANK&lt;/th&gt;
      &lt;td&gt;
          &lt;div class="containers"&gt;
              &lt;select name="bank"&gt;
              &lt;?php foreach($bankdata as $bank){
                  echo '&lt;option value="'.$bank['id'].'"&gt;'.$bank['bank'].'&lt;/option&gt;';
              } ?&gt;
              &lt;/select&gt;
          &lt;/div&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>My database structure (see <a href="http://prntscr.com/74mi6p" rel="nofollow noreferrer">here</a>),</p>
  
  <pre>id    bank
  ------------
  0     Bank 1
  1     Bank 2
  2     Bank 3
  3     Bank 4
  4     Bank 5
  </pre>