php - Multiple values in Database separated by comma show these values one by one in Dropdown list using Codeigniter -


i have shopping store many products have multiple color values or products have multiple size values like. small,medium,large,xl

i'm store these values in database column , want show 1 one in dropdown select list. using codeigniter nothing show in dropdown list. here code.

model

public function get_all()     {         $this->db->select()                  ->from('vendor_products')                  ->order_by(1,'desc');         $data = $this->db->get();         $query = $data->result_array();          foreach ($query $result) {              if (!empty($result['color_values'])) {                 $result['color_values'] = explode('||' , $result['color_values']);             }             if (!empty($result['size_values'])) {                 $result['size_values'] = explode('||',$result['size_values']);             }         }         return $query;     } 

controller

public function index()     {         $this->load->model('cartm');         $data['posts'] = $this->cartm->get_all();         $this->load->view('cart/index',$data);     } 

view

<?php if($post['color_values']) : ?>                         <p>color: <select>     <?php foreach($post['color_values'] $optvalue) :          $option_array = explode('::', $optvalue);     ?>     <option value="<?=$option_array[0]?>"><?=$option_array[1]?></option>     <?php endforeach; ?>                         </select></p>     <?php endif; ?>      <?php if($post['size_values']) : ?>                         <p>size: <select>     <?php foreach($post['size_values']  $optsize) :          $opt_size = explode('::', $optsize)     ?>      <option value="<?=$opt_size[0]?>"><?=$opt_size[1];?></option>     <?php endforeach;?>                         </select></p>     <?php endif; ?> 

what mean in comment is, manipulating array $result, returning $query. so, manipulation has no affect. should this:

public function get_all()     {         $this->db->select()                  ->from('vendor_products')                  ->order_by(1,'desc');         $data = $this->db->get();         $query = $data->result_array();          foreach ($query $k => $result) {              if (!empty($result['color_values'])) {                 $query[$k]['color_values'] = explode('||' , $result['color_values']);             }             if (!empty($result['size_values'])) {                 $query[$k]['size_values'] = explode('||',$result['size_values']);             }         }         return $query;     } 

and then, before writing more code, check in controller values need in view:

public function index()     {         $this->load->model('cartm');         $data['posts'] = $this->cartm->get_all();          print "<pre>";         print_r($data);         print "</pre>";         // $this->load->view('cart/index',$data);     } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -