Reputation: 57
i am newbie in Codeigniter. This is one of my model function. there was a list of the data (student name,student ID,gender)with the same Course_ID.how do i print out all the list?is add in the loop function? Below function only cant print out one row of data.
> public function viewMark($Course_ID)
> {
> //while($Course_ID != NULL)
> if($Course_ID != NULL)
> {
> $this->db->select('*');
> $this->db->where('mark.Course_ID',$Course_ID);
> $this->db->from('mark');
>
> $query = $this->db->get();
>
> return $query->row();
>
> }
> }
Upvotes: 2
Views: 589
Reputation: 864
public function viewMark($Course_ID)
{
if(isset($Course_ID) && $Course_ID != NULL)
{
$this->db->select('*');
$this->db->where('mark.Course_ID',$Course_ID);
$this->db->from('mark');
$query = $this->db->get();
return $query->result();
}
}
Controller
public function fun($Course_ID){
$this->load->model("your_model_class");
$data['db_data'] = $this->your_model_class->viewMark($Course_ID);
$this->load->view('page', $data);
}
in your view :
<?php foreach ($db_data as $row_data):?>
<?php echo $row_data->your_table_column_name?>
<?php endforeach ?>
Upvotes: 0
Reputation: 15609
Change
return $query->row();
to
return $query->result();
Then in your controller, you can do this:
public function whatever_this_is($Course_ID){
$this->load->model("yourmodel");
$data['mark'] = $this->yourmodel->viewMark($Course_ID);
$this->load->view('page', $data);
}
Then in your view:
foreach ($mark as $m):
echo $m->whatever."<br>";
echo $m->something."<br>";
endforeach;
Upvotes: 2