Index: branches/RC/core/units/general/country_states.php =================================================================== diff -u -N -r10098 -r10459 --- branches/RC/core/units/general/country_states.php (.../country_states.php) (revision 10098) +++ branches/RC/core/units/general/country_states.php (.../country_states.php) (revision 10459) @@ -18,26 +18,34 @@ */ function PopulateStates(&$event, $state_field, $country_field) { + static $country_states = Array (); + $object =& $event->getObject(); $country_abbr = $object->GetDBField($country_field); - if (!$country_abbr) return; - $country_id = $this->Conn->GetOne('SELECT DestId FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=1 AND DestAbbr = '.$this->Conn->qstr($country_abbr)); - if (!$country_id) return; + if (!$country_abbr) { + return ; + } - $query = - 'SELECT p.Translation as DestName, sd.DestAbbr - FROM '.TABLE_PREFIX.'StdDestinations AS sd - LEFT JOIN '.TABLE_PREFIX.'Phrase AS p - ON p.Phrase = sd.DestName - WHERE - DestType=2 AND DestParentId='.$country_id.' - AND - LanguageId = '.$this->Application->GetVar('m_lang').' - ORDER BY Translation'; + if (!array_key_exists($country_abbr, $country_states)) { + $sql = 'SELECT DestId + FROM '.TABLE_PREFIX.'StdDestinations + WHERE DestType = 1 AND DestAbbr = '.$this->Conn->qstr($country_abbr); + $country_id = $this->Conn->GetOne($sql); + if (!$country_id) { + return ; + } - $states = $this->Conn->GetCol($query, 'DestAbbr'); - $object->Fields[$state_field]['options'] = $states; + $sql = 'SELECT p.Translation as DestName, sd.DestAbbr + FROM ' . TABLE_PREFIX . 'StdDestinations AS sd + LEFT JOIN ' . TABLE_PREFIX . 'Phrase AS p ON p.Phrase = sd.DestName + WHERE DestType = 2 AND DestParentId = ' . $country_id . ' AND LanguageId = ' . $this->Application->GetVar('m_lang') . ' + ORDER BY Translation'; + + $country_states[$country_abbr] = $this->Conn->GetCol($sql, 'DestAbbr'); + } + + $object->Fields[$state_field]['options'] = $country_states[$country_abbr]; $object->Fields[$state_field]['options'][''] = ''; }