Welcome Guest, Not a member yet? Register   Sign In
need help formating JSON
#2

[eluser]bretticus[/eluser]
Your json code shows each result as an associative array within a larger array. Just format accordingly:

Code:
function get_location_list()
        {
            $location_list = array('results' => array());
            
            $query = $this->db->query('SELECT id, location FROM location');
            
            foreach ($query->result_array() as $row)
            {
                $value = $row['id'];
                $text = $row['location'];
                $location_list['results'][] = array('id' => $value, 'name' => $text);
            }
            echo json_encode($location_list);
            
            //return ;
                                        
        }


Messages In This Thread
need help formating JSON - by El Forum - 08-04-2010, 08:47 PM
need help formating JSON - by El Forum - 08-04-2010, 09:06 PM
need help formating JSON - by El Forum - 08-04-2010, 09:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB