• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! with pagination!!

#1
[eluser]Unknown[/eluser]
In controller I have this function which listing data from data base and also contains pagination. when I am removing the pagination code its working fine.

Code:
public function makeManagement($passed_data=NULL)
    {
          $data = array();
          if($passed_data!=NULL)
          $data =(array)$passed_data;
        
          $this->load->library('pagination');
          $query = $this->db->get('tbl_make');
          $a = $query->num_rows();
          $config['base_url'] = base_url().'index.php/admin/makeManagement/';
          $config['total_rows'] = $a;
          $config['per_page'] = '10';
          $config['uri_segment'] = 3;
          $config['full_tag_open'] = '<p>';
          $config['full_tag_close'] = '</p>';
          $this->pagination->initialize($config);
          $this->load->model('admin_model');
           [color=red]$data['makes'] = $this->admin_model->get_make($config['per_page'],$this->uri->segment(3));
          $this->load->view('make_management', $data);[/color]

    }

when I am calling this above function from another function that is saving data to data base then its fine, Here is the add function in controller.


Code:
public function addMakeProcess()
    {
        if(isset($_POST['addmake']) && $_POST['make_title']!="")
        {
            $this->load->model('admin_model');
            unset($_POST['addmake']);
            if($this->admin_model->insert_make($_POST))
            {
                $data['conf'] = "Make added sucessfully.";
                $this->makeManagement($data);
            }
            else
            {
                $data['error'] = "Unable to add new make, please try again.";
                $this->addMakeForm($data);
            }            
        }
        else
        {
            $data['error'] = "Invalid data, please make sure you have made proper entries.";
            $this->makeManagement($data);
        }        
    }

but when I call function "makeManagement($data)" (the first one) from another function namely deleteMake(); then I get an error that is:

A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/make_management.php
Line Number: 49

Here is the deleteMake() function code:

Code:
public function deleteMake($make_id=NULL)
    {
        if($make_id != NULL)
        {
          $this->load->model('admin_model');
          if($this->admin_model->remove_make($make_id))
          {
              $data['conf'] = "Make deleted sucessfully.";
             [color=red] $this->makeManagement($data);[/color]          
          }
          else
          {
              $data['error'] = "Unable to delete make, please try again.";
              $this->makeManagement($data);
          }
        }
        else
        {
            $data['error'] = "Invalid data, please make sure you have made proper entries.";
            $this->makeManagement($data);
        }
    }

Here is the model code for deleting:

Code:
function remove_make($id)
    {
        try
        {
            $this->db->where('make_id',$id);
            $this->db->delete('tbl_make');
            return true;
        }
        catch(Exception $e)
        {
            return false;
        }
    }


Here is the model code for lsitng recodrs:

Code:
function get_make($perPage, $uri)
    {
          $this->db->order_by('make_id','asc');
          $query = $this->db->get('tbl_make', $perPage, $uri);
          if($query->num_rows() > 0)
          return $query->result_array();
          else
          return false;
    }


What is wrong with this please help I am really stuck with this.

Thanks in advance

#2
[eluser]Aken[/eluser]
You're trying to loop through an array in your "views/make_management.php" view file, but it is not reaching the view as an array, but something else. Find where that array is supposed to come from, then find out why it isn't an array at all.

#3
[eluser]Unknown[/eluser]
I have got the point I was sending wrong argument to the model I come up with two changes in the controller and it solved my problem.... thought that might be helpful for others...
Here goes the two changes that I made to the function in controller that contain the pagination.


Code:
public function makeManagement($passed_data=NULL,$page=NULL)
    {
          $data = array();
          if($passed_data!=NULL)
          $data =(array)$passed_data;
        
          $this->load->library('pagination');
          $query = $this->db->get('tbl_make');
          $a = $query->num_rows();
          $config['base_url'] = base_url().'index.php/admin/makeManagement/';
          $config['total_rows'] = $a;
          $config['per_page'] = '10';
          $config['uri_segment'] = 3;
          $config['full_tag_open'] = '<p>';
          $config['full_tag_close'] = '</p>';
          $this->pagination->initialize($config);
          $this->load->model('admin_model');
          $data['makes'] =$this->admin_model->get_make($config['per_page'],$page);
          $this->load->view('make_management', $data);


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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