Welcome Guest, Not a member yet? Register   Sign In
Another noob question on passing $data
#5

[eluser]TheFuzzy0ne[/eluser]
Code:
# Model method
function get_country()
{
    $sql = "SELECT * FROM country";
    $result = $this->db->query($sql);
    return $result->result_array(); # Return an array.
}

Assign values individually.
Code:
# Controller - Method 1

$country = $this->my_model->get_country();

$data = array();
$data['Name'] = $country['Name'];
$data['Region'] = $country['Region'];
$data['GovernmentForm'] = $country['GovernmentForm'];

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

Use list().
Code:
# Controller - Method 2

$country = $this->my_model->get_country();

$data = array();
list($data['Name'], $data['Region'], $data['GovernmentForm']) = $country;

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

Merge the results.
Code:
# Controller - Method 3

$country = $this->my_model->get_country();

$data = array();
$data = array_merge($data, $country);

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

None of this code has been tested, it serves simply to illustrate my suggestions. It's advisable to add some more logic to check for results where necessary, or to set the defaults.


Messages In This Thread
Another noob question on passing $data - by El Forum - 04-05-2009, 11:47 PM
Another noob question on passing $data - by El Forum - 04-06-2009, 12:20 AM
Another noob question on passing $data - by El Forum - 04-06-2009, 05:39 AM
Another noob question on passing $data - by El Forum - 04-06-2009, 05:54 AM
Another noob question on passing $data - by El Forum - 04-06-2009, 06:29 AM
Another noob question on passing $data - by El Forum - 04-06-2009, 07:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB