Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: Looping, Setting and Updating! Oh My.

$
0
0

It would depend a little bit on what Bing was doing.  e.g. if it returned a 404 or 500 error, you could watch for that using cfhttp.statusCode. 

 

Or if it still returns a bunch of XML, you could check for that being in the correct format.

 

Or just wrap the whole thing in a try-catch (usually a good idea when calling an external website anyway).

 

This code combines the first and last ideas.

 

<cfloop query="ListingShort">

    <cftry>

        <!---get the data back from Bing--->

        <cfhttp url="http://dev.virtualearth.net/REST/v1/Locations/US/NV/#ListingShort.Zip_ Code#/#ListingShort.City#/#ListingShort.Street_Number#%20#ListingShort .Street_Name#?o=xml&key=AgM3wR0ojSpxYaJeh6WS7p2kcckECqVQ5HkrweFcZCcyOj E3mYVvIrF_WzbETMeb" timeout = "2" method="GET">

 

        <cfif val(cfhttp.statusCode) EQ 200>  <!--- will turn "200 OK" into 200 --->

            <cfset xbinglocation = xmlparse(cfhttp.filecontent)>

            <cfset lat=xbinglocation.Response.ResourceSets.ResourceSet.Resources.Locatio n.Point.Latitude.XmlText>

            <cfset long=xbinglocation.Response.ResourceSets.ResourceSet.Resources.Locati on.Point.Longitude.XmlText>

 

             <!---update the latitude and longitude fields--->

            <cfquery datasource="square" name="addGeo">

                UPDATE glvar_daily_bulk

                SET Latitude =<cfqueryparam value="#lat#" cfsqltype="cf_sql_float">,

                Longitude = <cfqueryparam value="#long#" cfsqltype="cf_sql_float">

                WHERE MLS_Id = <cfqueryparam value="#ListingShort.MLS_Id#" cfsqltype="cf_sql_integer">

            </cfquery>

        </cfif>

       

        <cfcatch type="any">

            <cfoutput>Oops, an error on row ID = #ListingShort.MLS_Id#</cfoutput>  <cfdump var="#cfcatch#">

        </cfcatch>

    </cftry>

</cfloop>


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>