Welcome Guest, Not a member yet? Register   Sign In
multiple data sets passed from one controller to one view
#1

[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
#2

[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!
#3

[eluser]Unknown[/eluser]
thanks

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

[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);




Theme © iAndrew 2016 - Forum software by © MyBB