US Zip code search in CGridView


I’m trying to create a ZIP code field in a CGridView, so when I search for a specific ZIP code it’d return the closest addresses in (ie) a 10mile radius.

has anybody heard of an extension or anything like that?



Does your zip table have the geo-coordinates?

Are your addresses geo-coded?

Here how I use it in the model. I though of extension but did not buy it.

$sql = "SELECT P.*,

               	3956 * 2 * ASIN(SQRT( POWER(SIN(($lat - lat) * pi()/180 / 2), 2)

               	+ COS($lat * pi()/180) * COS(lat * pi()/180)

               	* POWER(SIN(($lon - lon) * pi()/180 / 2), 2) )) AS distance

          	FROM fsd.products P

        	HAVING distance <= $miles

      	ORDER BY distance, impression LIMIT $limit";

    $dataReader = Yii::app()->db->createCommand($sql)->query();

    $data = $dataReader->readAll();

Unfortunately I only have the ZIP code in my table right now, so first I have to find the coordinates (so it will be an extra step :confused:

thanks for the query btw


That is a pretty good query… Thanks for it Pradham!!!