I’m trying to query the country table with the below query to print all countries with the corresponding cities. Now i’m getting a duplicated country object for each city instead of have one country object for all cities.
$all = ORM::factory('country')->select('cities.*')->join('cities','LEFT')->on('country.id', '=', 'country_id' )->find-all();
foreach ($all as $country) {
echo $caountry->name;
foreach($country->cities as $city ){
echo $city->name;
}
}
Appreciate your help,
AA
If you are using MySQL and only need the name of the city, you can use GROUP_CONCAT function and then convert it to array using PHP’s explode.