• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selected = Selected not working...!!!

#1
[eluser]Roy MJ[/eluser]
Hi Can anyone tell me whether this is the right method for displayin selected value in select box??

Code:
<div>
<label>Product Group<span class="mandatory">*</span></label>
<select name="product_group" id="product_group" class="list_1">
    <option value="">- - Select Category - -</option>
    &lt;?php foreach($this->data['productcategory'] as $row)    { ?&gt;
    <option value="&lt;?php echo $row->category_name ?&gt;" &lt;?php echo set_select('product_group',$row->category_name);?&gt; >&lt;?php echo $row->category_name ?&gt;</option>
    &lt;?php    }    ?&gt;
</select>
                                  
<span style="color:#FFFFFF; font-size:10px">&lt;?php echo form_error('product_group'); ?&gt;</span>
</div>

Controller is as follows:

Code:
function edit(){
        //if data submitted
        [b]$this->data['productcategory'] = $this->Mypackages_model->select_category();[/b]
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
            $member_name = $this->data['screenname'] = $row->screenname;
        }
        if($this->input->post('Submit')){
            $config = array(
                           array('field'   => 'package_title','label'   => 'Product Name', 'rules'   => 'trim|required'),
                           array('field'   => 'price','label'   => 'Price', 'rules'   => 'trim|numeric|required'),
                           array('field'   => 'product_group','label'   => 'Group', 'rules'   => 'trim|required')
                        );
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                $row    =    array();
                $this->load->view('mypackages/edit','');
                
            }else{
                if($_FILES['userfile']['name']!=''){
                   //upload thumbnail
                    $config['upload_path'] = site_path().'packages/';
                    $config['allowed_types'] = 'gif|jpg|png';
                    $config['max_size']    = '1024';
                    $this->load->library('upload', $config);    
                    if ( ! $this->upload->do_upload())
                    {
                        $data['alert'] = $this->upload->display_errors();                        
                        $this->load->view('mypackages/edit', $data);
                    }    
                    else
                    {
                        $upload_data = $this->upload->data();
                        
                        $filename = $upload_data['file_name'];
                        $width = $upload_data['image_width'];
                        $height = $upload_data['image_height'];
                        $config1 = array();
                        $this->load->library('image_lib');
                        $config1['source_image'] = site_path().'packages/'.$filename;
                        $config1['maintain_ratio'] = TRUE;
                        $config1['width'] = 83;
                        $config1['height'] = 66;
                        $config1['create_thumb'] = TRUE;
                        $config1['thumb_marker'] = 'thumb_';
                        $config1['maintain_ratio'] = FALSE;
                        $this->image_lib->initialize($config1);
                        $this->image_lib->resize();
                        $this->remove_existing_thumb($this->input->post('selected_package'));
                        $this->Mypackages_model->save('Edit', $filename, '' );
                        redirect('mypackages/index/'.$this->input->post('pgoffset'));
                    }
                }else{
                    $this->Mypackages_model->save('Edit', '', '');
                    redirect('mypackages/index/'.$this->input->post('pgoffset'));
                }
            }
        }else{
            $selected_package    =    $this->input->post('selected_package');
            
            
            $row    =    array();
            $row    =      $this->Mypackages_model->get_selected($selected_package);
            $data['package_title'] = $row->package_title;
            $data['price'] = $row->price;
            $data['product_group'] = $row->product_group;
            $data['imagefile'] = $row->imagefile;
            $data['selected_package'] = $selected_package;
            
            $data['pgoffset'] = $this->input->post('pgoffset');
            
            $this->load->view('mypackages/edit', $data);
        }
    }

Model :

Code:
function get_selected($selected_package)
    {
        $result_selected    =    $this->db->query("SELECT * FROM packages WHERE id='$selected_package'");
        return $result_selected->row();
    }
function select_category()
    {
        $this->db->select('category_id,category_name');
        $this->db->order_by('category_id',"desc");
        $result_productcategory = $this->db->get('product_category');
        return $result_productcategory->result();
    }

Plz help..!!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.