Welcome Guest, Not a member yet? Register   Sign In
Using dynamic data for array creation
#1

[eluser]Wittner[/eluser]
Hi,

I had a query which went something like this:
(All of the below code is rough code for illustration purposes)

Code:
== CONTROLLER ==
// DB data
$inputData = array(
    'field1' => $field1,
    'field2' => $field2
);

$this->model->update_db($inputData);

== MODEL ==
$this->db->update('tablename', $inputData);

.. all of which worked fine

Now I want to dynamically create the array data in the controller from a query in a model, something like this:

Code:
== CONTROLLER ==
$inputData = $this->whatever_model->get_my_data();
$this->model->update_db($inputData);

== MODEL ==
$this->db->update('tablename', $inputData);

I think the result in the new version is begin returned as an object and not an array. Can anyone tell me the proper approach for this?

cheers,

Wittner
#2

[eluser]flaky[/eluser]
Code:
return $this->db->get('tablename')->result_array();//returns array
#3

[eluser]Wittner[/eluser]
Thanks flaky. Slightly confused as to how to use this. Does that line belong in the model or the controller?
#4

[eluser]flaky[/eluser]
in the model
Code:
public function get_my_data(){
    return $this->db->get('tablename')->result_array();//returns array
}
#5

[eluser]Wittner[/eluser]
Gotcha! Thanks mate,

cheers,

Wittner

[solved]




Theme © iAndrew 2016 - Forum software by © MyBB