public function __construct($user_id = 0) { parent::__construct('user', $user_id); if ($user_id) { $sql = sprintf("SELECT region_id FROM user_region WHERE user_id=%d AND region_type=%d ORDER BY updated_date DESC LIMIT 1", $user_id, REGION_CITY); $city_id = db()->Get_Cell($sql); $city = new City($city_id); $this->city_id = $city_id; $this->county_id = $city->county_id(); $this->state_id = $city->state_id(); } }
public static function get_city_list_by_zip($zip) { $records = array(); $sql = "SELECT prime_zip, city_name FROM ref_city WHERE zip='{$zip}' ORDER BY city_name, zip"; $pre_data = db()->Get_Table($sql); if (!empty($pre_data)) { foreach ($pre_data as $pre_row) { $prime_zip = $pre_row['prime_zip']; $city_name = $pre_row['city_name']; $sql = "SELECT city_id FROM ref_city WHERE zip='{$prime_zip}' AND city_name='{$city_name}'"; $data = db()->Get_Table($sql); if (!empty($data)) { foreach ($data as $row) { $record = new City($row['city_id']); $record->retrieve_record($row['city_id']); $records[] = array('key' => $record->id(), 'value' => $record->city_name(), 'county_id' => $record->county_id(), 'state_id' => $record->state_id()); } } } } return $records; }