Welcome Guest, Not a member yet? Register   Sign In
Exploding an array in the view.
#1

[eluser]afro[/eluser]
Hi guys, can someone help me in solving this problem
I have this function in the model, it should return an array of
the Staff details and explored in the view. The problem is that it display the word 'Array' on the view.
In stead of the results returned from the db
model
Code:
function staffdetails()
{
    
//getting the staff id//
   $q1 = $this->db->select('StaffId');
   $this->db->from('staff');
   $this->db->where('Username', $this->input->post('username'));
   $staff['StaffId'] = $q1->get()->result();
      
//getting the staff name//
  $q2 = $this->db->select('FirstName, Surname, LastName');
  $this->db->from('staff');
  $this->db->where('Username', $this->input->post('username'));
  $staff['StaffName'] = $q2->get()->result();
                
                
//getting the staff department//
  $q3 = $this->db->select('Department');
  $this->db->from('staff');
  $this->db->where('Username', $this->input->post('username'));
  $staff['Department'] = $q3->get()->result();
                
//getting the staff leave balance//
  $q4 = $this->db->select('LeaveBalance');
  $this->db->from('staff');
  $this->db->where('Username', $this->input->post('username'));
  $staff['LeaveBalance'] = $q4->get()->result();
                
//return staff array//
  return $staff;
    }
the controller
Code:
if($query)
{
    //load staff details ie, staffid, staffname, leave balance and department//
    $this->load->model('Register_model');
    $results = $this->Register_model->staffdetails();
            
    $data['Id'] = $results['StaffId'];
    $data['Name'] = $results['StaffName'];
    $data['Depart'] = $results['Department'];
    $data['Balance'] = $results['LeaveBalance'];
            
    $this->load->view('leave', $data);
}
In the view i have echoed them this way

Code:
<input type="text" name="staffid" maxlength="10" id="staffid" value="<?php echo $Id; ?>"/>
<input type="text" name="staffname" maxlength="70" value="<?php echo $Name; ?>"/>
<input type="text" name="department" maxlength="70" value="<?php echo $Depart; ?>"/>
<input type="text" name="leavebalance" maxlength="30" value="<?php echo $Balance; ?>"
#2

[eluser]michalsn[/eluser]
http://ellislab.com/codeigniter/user-gui...sults.html

You must specify which variable from database you want to display in a view. For example:
Code:
<input type="text" name="staffid" maxlength="10" id="staffid" value="<?php echo $Id[0]->StaffId; ?>"/>
#3

[eluser]afro[/eluser]
michalsn

Thanks a lot for your help, its now working well




Theme © iAndrew 2016 - Forum software by © MyBB