Welcome Guest, Not a member yet? Register   Sign In
How would I "convert" this mysql_query to CI's active record?
#7

[eluser]Isern Palaus[/eluser]
And taking the bubbafoley code I can do it with less code:

Code:
function get_client()
{
    if(false === $this->input->is_ajax_request())
        redirect(""); // redirect to the start of the page

    $result = array();

    $query = $this->db->select('name')->get('clients')->result_array();
    
    foreach($query as $row)
        $result[] = $row["name"];

    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    
    echo json_encode($result);
}

I've changed the array push, take a look in PHP manual:
Quote:PHP manual says: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.


Messages In This Thread
How would I "convert" this mysql_query to CI's active record? - by El Forum - 03-15-2011, 05:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB