Skip to content

Instantly share code, notes, and snippets.

@thyseus
Created March 25, 2013 13:33
Show Gist options
  • Select an option

  • Save thyseus/5237121 to your computer and use it in GitHub Desktop.

Select an option

Save thyseus/5237121 to your computer and use it in GitHub Desktop.
function actionFetchAll($term)
{
$query = sprintf(
"select CityName from geodata
where CityName like '%%%s%%'
group by CityName
order by CityName",
$term);
$result = Yii::app()->db->createCommand($query)->queryAll();
$cities = array();
foreach($result as $row)
$cities[] = $row['CityName'];
echo json_encode($cities);
}
<?php Yii::app()->clientScript->registerScript('postal', "
$('#Store_zipcode').blur(function() {
$.ajax({
'url': '".Yii::app()->controller->createUrl('//store/fetchZipcode')."',
'dataType': 'json',
'data': $(this),
'success': function(response) {
$('#Store_city').val(response.CityName);
$('#Store_latitude').val(response.Latitude);
$('#Store_longitude').val(response.Longitude);
$('#Store_country').val(response.CountyName);
}
});
});
"); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment