Welcome Guest, Not a member yet? Register   Sign In
Process result from DB in Controller
#1

[eluser]SniffTheGlove[/eluser]
Hello,

Struggling to get my head around the DB access code in CI and need some help.

I am running a function in my model to extract a single value from a MySQL table.

Code:
function get_Geo_Location_Latitude()
{
    $query = $this->db->query('SELECT geo_defaults_value FROM geo_defaults WHERE geo_defaults_descriptor = "Latitude" ');
    if ($query->num_rows() == 0)
    {
        //show_error('Database is empty!');
    }
    else{  
        return $query->result();
    }
}

In the controller I can assign the result to a variable
Code:
$main_var['Latitude'] = $this->model_home->get_Geo_Location_Latitude();
that can be passed to the view which works fine but I want to assign the actual value from the query (which will be 47.345612) to a variable called $latitude that I can work with in the controller but I can not see how to access the variable as the result returns an object, if I use return $query->result_array(); then an array is returned but I still can not get access to it. I have tried many ways but stumped.

Any ideas?


Messages In This Thread
Process result from DB in Controller - by El Forum - 07-25-2011, 05:42 PM
Process result from DB in Controller - by El Forum - 07-26-2011, 09:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB