title: codeigniter - populate dropdown list with query result using json
body: <p>I have a dropdown list, that when changed passes the value to a controller.</p>
  
  <p>This controller, through the model then runs a query that returns multiple results.</p>
  
  <p>I need to somehow populate my dropdown list with the results of the query.</p>
  
  <p>my syntax is:</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>  function GetDeliveryAddressfromCustomer(){
  
      $this-&gt;load-&gt;model('Sales_model');
      if (isset($_POST['data'])){
          $q = strtolower($_POST['data']);
          $data = $this-&gt;Sales_model-&gt;GetDeliveryAddressfromCustomer($q);
          $this-&gt;output-&gt;set_content_type('application/json')-&gt;set_output(json_encode($data));
      }
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>  function GetDeliveryAddressfromCustomer($q){
      $this-&gt;db-&gt;select('deliveryaddress');
      $this-&gt;db-&gt;where('Account', $q);
      $query = $this-&gt;db-&gt;get('Client');
      if($query-&gt;num_rows &gt; 0){
          foreach ($query-&gt;result_array() as $row){
              $row_set[] = htmlentities(stripslashes($row['deliveryaddress'])); 
         }
         return $row_set;
      }
    }
  </code></pre>
  
  <p><strong>View JS</strong></p>
  
  <pre><code> $.post('GetDeliveryAddressfromCustomer', {data:selectedObj.value},function(result) { 
    var selcust = selectedObj.value;
  
    //what to put here to pupulate dropdown list
  
    }); 
  </code></pre>
  
  <p><strong>View select</strong></p>
  
  <pre><code> &lt;select id="deliveryaddress" name="deliveryaddress" data-mini="true" data-theme="a"&gt;
     &lt;option value="0"&gt;&lt;/option&gt;
   &lt;/select&gt;
  </code></pre>
  
  <p>the error is:  <code>Trying to get property of non-object</code></p>
  
  <p>I presume the error is from the multiple results being returned. selectedObj.value is an array not a value.</p>
  
  <p>I am less worried about the part of pupulating the dropdown but if you have advice please provide it.</p>
  
  <p>Thanks,
  Ryan</p>