[eluser]daweb[/eluser]
Usually.. excuse me about english :-(
I have a dynamic query with some field results (maybe cod, title) or (maybe cod, title, order) or etc... It depends on the query.
I want to build an array with the result of query
$myarray = [title] = 'MyTitle' [cod] = 'MyCod' ext...
Now, in my model code:
Code:
$query = $this->db->get('table'); // with some where clauses
if($query->num_rows() > 0 ) :
$query_info = array(
'list_field' => $query->list_fields(),
'result' => $query->result()
);
return $query_info;
end;
And in my library code:
Code:
$result = $this->CI->layout_Model->get_my_query();
$daweb_array = array();
# costruzione dinamica dell'array
foreach($result['list_field'] as $key => $field) :
$daweb_array['name_of_array_for_template_library'][$field] = $result['result'][0]->$field;
endforeach;
Code:
$result['result'][0]->$field
Is it the best way to do that?
Please help me CI people!
Thank you guys
PS. It works, I wanna know if it is elegant and the best way to do that