Browsing posts in: php

Passing two arrays into a view (codeigniter)

Here is a post which will show you how to pass two arrays into a view in codeigniter:

Controller:

function dashboard(){
 $this->load->model('golf_db');
 $user_id = $this->session->userdata('user_id');
 $data['last_round'] = $this->golf_db->get_last_round($user_id);
 $data['leaderboard'] = $this->golf_db->get_leaderboard();
 $this->load->view('dashboard',$data);
 }

View:

< ?php echo $last_round[0]->round_week; //echo $round_week; ?>
< ?php echo $last_round[0]->round_course; ?>
< ?php echo $last_round[0]->round_score; ?>

The Fix

Instead of using $last_round->last round you need to access the array within the array with $last_round[0]->last round. With the 0 moving to 1 when you are on the second array in the $data variable. Hope this helps!