Included script fails to process
A homegrown banner ad script that displays banners in random order works fine when ran alone. Any of three ads will appear on the page. However, when the file is included in another using CFINCLUDE the random part fails. Only one ad appears -- apparently the one with the lowest ID.
Why would the included file behave differently? How can this be fixed?
This is CF8.
Standalone file: www.portsmouthnh.com/cfm/test.cfm and below. Reload it several times and a different ad will appear
As included: www.portsmouthnh.com/downtown/. Reload it and the same ad always appears.
(In local testing, the script works fine, but not on the server.)
I'm baffled. Any help will be appreciated.
<cfparam name="request.page" default="all">
<!--- start banner ad query --->
<!--- get ads --->
<cfif IsDefined("request.page")>
<cfquery datasource="yellowpages" name="qBannerAds" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
SELECT *
FROM Ads
WHERE Page = '#Request.Page#'
AND (Show = 'yes'
AND Adtype = 'banner'
AND EndDate >= #createODBCDate(now())#)
</cfquery>
<cfif qBannerAds.RecordCount GT 0>
<!--- create a list --->
<cfset StartList = "">
<cfloop query="qBannerAds">
<cfset StartList = #ListAppend(StartList, AdID, ",")#>
</cfloop>
<!--- Get a random id --->
<cfset LengthOfList = #ListLen(StartList)#>
<cfset RandomPosition = #RandRange(1,LengthOfList)#>
<cfset RandomID = #ListGetAt(StartList, RandomPosition)#>
<!--- Select the ad --->
<cfquery datasource="yellowpages" name="qBannerAds2" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
SELECT *
FROM Ads
WHERE AdID = #RandomID#
</cfquery>
<cfoutput query="qBannerAds2" maxrows="1">
<!--- create space-free name for Google Analytics tracking --->
<cfset GoogleName = #replace(Name, ' ', '_',"all")#>
<a href="#link#" onClick="javascript: pageTracker._trackPageview('/outgoing/#GoogleName#');"><img src="#image#" hspace=2 vspace=1 border=0 alt="#Name#" title="#Name#"></a> </cfoutput>
</cfif>
