Not get the correct parent from database it pick the first record in child db

In the View.php in front end
<?php
if($listingAddress):
if(!empty($listingLocation)):
echo ‘

’.A::t(‘directory’, ‘Location’).’:
’;
echo ‘
’.$listingLocation.’
’;
endif;

In the ListningsController.php

                // Get all locations
                $regionName = '';
                $subLocations = array();
                $result = Regions::model()->find(CConfig::get('db.prefix').'regions.id = :id', array('i:id'=>$listing->region_id));
                $region = !empty($result) ? $result->getFieldsAsArray() : array();
                $this->_view->listingLocation = !empty($region['name']) ? $region['name'] : '';

                $result = Regions::model()->find('parent_id = :parent_id', array('i:parent_id'=>$listing->region_id));
                $parentRegion = !empty($result) ? $result->getFieldsAsArray() : array();
                $this->_view->listingLocation .= !empty($parentRegion['name']) ? ' / '.$parentRegion['name'] : '';
			}

The table “region_translations” has: id, region_id, name
table “regions” has: id, region_id

Sponsor our Newsletter | Privacy Policy | Terms of Service