Welcome Guest, Not a member yet? Register   Sign In
Retrieving problem..!!!
#1

[eluser]Roy MJ[/eluser]
Hi,
Can anyone tell me what im doing wrong. Im trying to get value from database for editing purpose. But error showing :

Code:
<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: productcategory</p>
<p>Filename: mypackages/edit.php</p>

<p>Line Number: 98</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Invalid argument supplied for foreach()</p>
<p>Filename: mypackages/edit.php</p>
<p>Line Number: 98</p>

The controller which im using to get the data is as follows:

Code:
$this->data['productcategory'] = $this->Mypackages_model->select_category();
$this->data['productstack'] = $this->Mypackages_model->select_stack();

The model part is as follows:

Code:
function select_stack()
    {
        $this->db->select('id,product_name');
        $this->db->order_by('product_name',"asc");
        $result_product = $this->db->get('product');
        return $result_product->result();
    }
    
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();
    }

The view is as follows:

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($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>
</div>
                            
<div>
<label>Stack<span class="mandatory">*</span></label>
<select id="product_id" name="product_id" class="list_1" >
<option value="">- - Select Stack - -</option>
&lt;?php    foreach($productstack as $row)    {?&gt;
<option value="&lt;?php echo $row->product_name?&gt;" &lt;?php echo set_select('product_id',$row->product_name);?&gt; >&lt;?php echo $row->product_name?&gt;</option>
&lt;?php } ?&gt;
<option value="11111"> - - Other - - </option>
</select>

</div>

Why is it showing undefined error?.. Its working fine for add page. This is while editing. But the select box values are from the same table and its value is static.
#2

[eluser]InsiteFX[/eluser]
Show your whole Controller code!

InsiteFX
#3

[eluser]Roy MJ[/eluser]
the whole controller..

Code:
class Mypackages extends Controller {
    function Mypackages(){
        parent::Controller();
        $this->load->model('Mypackages_model');
        $this->load->model('Aboutus_model');
        $this->load->model('Profile_model');
        $this->load->helper(array('form'));
        $this->load->library(array('form_validation','pagination'));
        $this->get_common();
    }
    function index($pgoffset=''){
    
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $config['per_page'] = $this->config->item('records_per_page');
            $config['total_rows'] = $this->Mypackages_model->get_total();
            $config['base_url'] = base_url().'index.php/mypackages/index/';
            $config['uri_segment'] = 3;
            $data['count_no'] = ($this->uri->segment(3)=='')? 0 : $this->uri->segment(3);
            $data['events']=  $this->Mypackages_model->get_all($config['per_page'], $pgoffset);
            $data['pgoffset'] = $pgoffset;
            $this->pagination->initialize($config);
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
            $this->load->view('mypackages/list', $data);
        }
        else{
            $data['alert'] = "Not Logged in..!! Please login to access the features";
            $this->load->view('profile/signin', $data);
        }
    }
    
    function add(){
        //if data submitted ' '
        $this->data['productcategory'] = $this->Mypackages_model->select_category();
        $this->data['productstack'] = $this->Mypackages_model->select_stack();        
        $row    =      $this->Mypackages_model->get_user($this->session->userdata('user_id'));
        $this->data['username'] = $row->username;
        if($this->input->post('Submit')){
            
            $product_id = $_REQUEST['product_id'];
            if($product_id!=NULL && $product_id!=11111){
            $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'),
                           array('field'   => 'product_id','label'   => 'Stack', 'rules'   => 'trim|required')
                        );
                        }
                    else{
                        $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'),
                           array('field'   => 'product_idd','label'   => 'Stack', 'rules'   => 'trim|required')
                        );        
                    }
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('mypackages/add', $this->data);
            }else{
                    if($_FILES['userfile']['name']!=''){
                   //upload thumbnail
                    $config['upload_path'] = site_path().'packages/';
                    //$config['upload_path'] = 'C://xampp/htdocs/paul/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/add', $this->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['maintain_ratio'] = FALSE;
                        $config1['thumb_marker'] = 'thumb_';
                        $this->image_lib->initialize($config1);
                        $this->image_lib->resize();
                        
                        $this->Mypackages_model->save('Add', $filename);
                        redirect('mypackages');
                    }
                }else{
                    $this->Mypackages_model->save('Add', '');
                    redirect('mypackages');
                }
            }
        }else{
                $this->load->view('mypackages/add', $this->data);
        }
        
    }
#4

[eluser]Roy MJ[/eluser]
continued...

Code:
function edit(){
        //if data submitted
        $this->data['productcategory'] = $this->Mypackages_model->select_category();
        $this->data['productstack'] = $this->Mypackages_model->select_stack();    
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
        }
        if($this->input->post('Submit')){
            $product_id = $_REQUEST['product_id'];
            if($product_id!=NULL && $product_id!=11111){
            $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'),
                           array('field'   => 'product_id','label'   => 'Stack', 'rules'   => 'trim|required')
                        );
                        }
                    else{
                        $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'),
                           array('field'   => 'product_idd','label'   => 'Stack', 'rules'   => 'trim|required')
                        );        
                    }
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                
                $row    =    array();
                $this->load->view('mypackages/edit', $data);
                
            }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, $state_n );
                        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['product_stack'] = $row->product_stack;
            $data['selected_package'] = $selected_package;
            
            $data['pgoffset'] = $this->input->post('pgoffset');
            
            $this->load->view('mypackages/edit', $data);
        }
    }
#5

[eluser]Roy MJ[/eluser]
Code:
function addtomarket(){
        //if data submitted
        $this->data['productcategory'] = $this->Mypackages_model->select_category();
        $this->data['productstack'] = $this->Mypackages_model->select_stack();    
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
            echo $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'),
                           array('field'   => 'product_id','label'   => 'Stack', 'rules'   => 'trim|required')
                        );
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                
                $row    =    array();
                $this->load->view('mypackages/addtomarket','');
                
            }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/addtomarket', $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('Addtomarket', $filename, $state_n );
                        redirect('mypackages/index/'.$this->input->post('pgoffset'));
                    }
                }else{
                    $this->Mypackages_model->save('Addtomarket', '', $member_name);
                    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['product_stack'] = $row->product_stack;
            $data['selected_package'] = $selected_package;
            
            $data['pgoffset'] = $this->input->post('pgoffset');
            
            $this->load->view('mypackages/addtomarket', $data);
        }
    }
    function delete($selected_package=''){
        $pgoffset    =    $this->input->post('pgoffset');
        $this->remove_existing_thumb($this->input->post('selected_package'));
        $this->Mypackages_model->delete();
        redirect('mypackages/index/'.$pgoffset);
    }
   function get_common(){
        if(($this->session->userdata('user_id'))!=NULL)
        {
            $row    =      $this->Profile_model->get_selected($this->session->userdata('user_id'));
            $this->data['username'] = $row->username;
        }
        $this->site_settings->get_site_settings();
        $this->data['productcategory'] = $this->Mypackages_model->select_category();
        $this->data['productstack'] = $this->Mypackages_model->select_stack();    
    }
    
}
#6

[eluser]Roy MJ[/eluser]
Ive figured put a way to show the list in select box, but im not sure whether this is the proper way. Displaying the selected thing as default is also not working with this.. Here is the view part..

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>
#7

[eluser]InsiteFX[/eluser]
You did not state what version of CI you were using, but if your using CI 2.0.X

Controller should be CI_Controller
and
Model should be CI_Model

InsiteFX
#8

[eluser]Roy MJ[/eluser]
Im using 1.7.2 or around that period...
#9

[eluser]InsiteFX[/eluser]
This is where all your problems are Filename: mypackages/edit.php

Your using $this->data in one function and $data in the other
add this and then change all $data to $this->data
Code:
class Mypackages extends Controller {

    var $data = array();
}

Also instead of this use this for all your views.
Code:
$this->load->vars($this->data);
$this->load->view('mypackages/addtomarket');

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB