CodeIgniter Forums
multiple data sets passed from one controller to one view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: multiple data sets passed from one controller to one view (/showthread.php?tid=31890)



multiple data sets passed from one controller to one view - El Forum - 07-05-2010

[eluser]Unknown[/eluser]
Hello

I'm making my first application with codeigniter, so I have a form that has several select inputs, some populated with data from their own table. I've been reading several tutorials and guides but can't grasp yet how to pass multiple data sets (each array with data from a different table) to populate my select inputs.

so I'm stuck in: $this->load->view('form', $data_from_table_city) but how can I pass the rest of the querys

Hope can have some help, thanks in advance


multiple data sets passed from one controller to one view - El Forum - 07-05-2010

[eluser]ulugbek[/eluser]
Hi!

Code:
// controller
$data['cities'] = $data_from_table_city; // data from table city
$data['states'] = $data_from_table_state; // data from table state
$data['countries'] = $data_from_table_country; // data from table country

$this->load->view('form', $data);

// view
echo '<select name="city">';
foreach($cities as $rows)
{
echo '<option value="'.$row->city_id.'">'.$row->city_name.'</option>';
}
echo '</select>';

I hope will help.
Good luck!


multiple data sets passed from one controller to one view - El Forum - 07-05-2010

[eluser]Unknown[/eluser]
thanks

nice answer. I just found some minutes ago array_merge() function, but your solution is much more simple. Smile


multiple data sets passed from one controller to one view - El Forum - 07-06-2010

[eluser]flaky[/eluser]
how about $this->load->vars()
Code:
$data['some_dropdowns_stuff'] = $this->some_model->get_dropdown();
$this->load->vars($data);

..
$some_other_data['sth'] = 'My TItle';
$this->load->vars($some_other_data);

..
$data['cities'] = $data_from_table_city; // data from table city
$data['states'] = $data_from_table_state; // data from table state
$data['countries'] = $data_from_table_country; // data from table country

$this->load->view('form', $data);