0

my controller is

function shiftstudentdetailsmultiple(){ $data['Show'] = $this->input->post('show[]'); $roll = $this->input->post('roll[]'); //echo sizeof($data1); for($i=0;$i<sizeof($roll);$i++) { $data['results'] = $this->FetchData->getstudentsdetailscouseandmultiple($roll[$i]); } $this->load->view('registrar/shift_student_view', $data); } 

and model is

function getstudentsdetailscouseandmultiple($Uniq_Id){ $this->db->select("sprd.Uniq_Id, sprd.Name, sprd.Uni_Roll_No, cd.Course_Name, bd.Branch_Name, sprd.Year, sprd.Session, sprd.Section, sprd.Fee_Status, sprd.Curr_Status"); $this->db->where("sprd.Uniq_Id",$Uniq_Id); $this->db->from("Students_Prim_Detals sprd"); $this->db->join('Course_Details cd', 'cd.Course_Id=sprd.Course_id'); $this->db->join('Branch_Details bd', 'bd.Branch_Id=sprd.Branch_id'); $query = $this->db->get(); if ($query->num_rows() > 0){ return $query->result(); } else { return false; } } 

when showing in view the fetching data showing only one time.. but in my database i have more then 4 entry when i print_r

 $data['results']=this->FetchData->getstudentsdetailscouseandmultiple($roll[$i]); 

the data showing correct .. when load only showing one data..the last entry..

 $this->load->view('registrar/shift_student_view', $data); 

1 Answer 1

1

Each time you call...

$data['results'] = $this->FetchData->getstudentsdetailscouseandmultiple($roll[$i]); 

you replace the value stored in $data['results'] with the new return. So only one return is sent to the view.

You will need to revise your controller along these lines.

$student_detail = array(); for($i=0;$i<sizeof($roll);$i++) { $student_detail[] = $this->FetchData->getstudentsdetailscouseandmultiple($roll[$i]); } $data['results'] = $student_detail; 

Then in your view you will have to loop through $results to display each item in the array.

foreach($results as $detail){ echo "Name: ". $detail->name; echo "Course: ". $detail->Course_Name; //etc... } 
Sign up to request clarification or add additional context in comments.

3 Comments

print_r($student_detail) result is Array ([0] => Array ( [0] => stdClass Object ( [Uniq_Id] => 2 [Name] => Devendra Chauhan [Uni_Roll_No] => 1006510014 [Course_Name] => B.Tech [Branch_Name] => CSE [Year] => 1 [Session] => 2016-2017 [Section] => A [Fee_Status] => Unpaid [Curr_Status] => Ex ) ) [1] => Array ( [0] => stdClass Object ( [Uniq_Id] => 545 [Name] => sdfdasf [Uni_Roll_No] => [Course_Name] => B.Tech [Branch_Name] => CSE [Year] => 1 [Session] => 2015-2016 [Section] => [Fee_Status] => Unpaid [Curr_Status] => Regular ) ) ) getting error on view is Trying to get property of non-object
why i am getting arrays in array. **Array ([0] => Array ( [0] => stdClass Object **
now its working fine.. the data is array into array and .. foreach($results as $detail) removes array only one.. for removing the inner array i have to put another foreach($deatil as $row) the it works fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.