Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm trying to open a web page based on zip code.

Status
Not open for further replies.

data58

MIS
Jul 19, 2007
1
US
I am trying to direct people to a web page based on zipcode (or group of zipcodes) and a default page if theres is not listed. Im using an access database.
I know You ask for a zip code. You check your database. You direct the user to the appropriate page. I'm new at coding in coldfusion. Can anyone help?
 
In your dB you'd need to map zip codes to their respective URL's so that when a user types in a zip code then you can query the dB and direct the user.

The query can be something like this:
SELECT PrimaryID, ZipCode, theLink
FROM Lookuptable
WHERE ZipCode = <cfqueryparam value="#FORM.ZipCode#" cfsqltype="CF_SQL_INTEGER" maxlength="5">

Note: If you're going to have Canadian zip codes then you're gonna need CF_SQL_VARCHAR instead of CF_SQL_INTEGER since Canadian ZipCodes allow alpha chars.

____________________________________
Just Imagine.
 
I've done exactly what you're trying to do. I have a table full of zip codes, if the user's zip matches one of the zips in the table I display promo 1, if not I display promo 2.

Code:
<cfif isDefined('form.zip')><cfset page.zip = form.zip></cfif>

<cfoutput>
                                    <cfif isDefined('page.zip')>
                                      <cfquery name="check_zip" datasource="#ds#">
                                      SELECT zip_codes FROM aad_zipcodes WHERE zip_codes = '#page.zip#'
                                      </cfquery>
                                      <cfif check_zip.recordcount GT 0>
                                        <cfquery name="get_promo" datasource="#ds#">
                                        SELECT promo_desc FROM aad_promotions WHERE promo_id = 1
                                        </cfquery>
                                        #get_promo.promo_desc#
                                        <cfelse>
                                        <cfquery name="get_promo" datasource="#ds#">
                                        SELECT promo_desc FROM aad_promotions WHERE promo_id = 2
                                        </cfquery>
                                        #get_promo.promo_desc#
                                      </cfif>
                                    </cfif>
                                </cfoutput>
Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top