CF does not provide advertisement components like ASP, but this does not mean that a powerful advertisement system cannot be created. Here I put a simple advertisement rotation system, it is also used in my CCF Forum. function, including the number of displays and the number of clicks. it is easy to expand on this basis and can be displayed in different categories. The following code only shows large advertisements. I just want to give you a chance to make a more powerful advertising system.
<! --- Determine whether there is Address transfer --->
<Cfif not IsDefined ("URL. ADID")>
<! --- Display advertisement by default --->
<Cflock timeout = "10">
<Cfparam name = "Application. AD" TYPE = "string" DEFAULT = ">
<CFIF ListLen (Application. AD) EQ 0>
<Cfquery name = "getID" datasource = "# DSN #">
Select adid from ad
</Cfquery>
<CFSET Application. AD = ValueList (getID. ADID)>
</CFIF>
<CFSET ThisAdID = ListGetAt (Application. AD, 1)>
<CFSET Application. AD = ListDeleteAt (Application. AD, 1)>
</CFLOCK>
<Cfquery name = "ad" datasource = "# DSN #">
Select * from ad
Where adid = '# ThisAdID #'
</Cfquery>
<! --- Update display times --->
<Cfset adshow = AD. SHOW + 1>
<Cfquery name = "updateshow" datasource = "# DSN #">
UPDATE AD
SET show = '# ADSHOW #'
Where ADID = '# AD. ADID #'
</Cfquery>
<! --- Display advertisement --->
<A href = "javascript: location. reload ()"> refresh </a> <p>
<Cfoutput query = "ad">
<A href = "ad. cfm? ADID = # URLEncodedFormat (ADID) # "title =" # title # "target =" _ blank "> </ a> <p>
<Br>
</Cfoutput>
<Cfelse>
<! --- If a parameter is passed --->
<Cfquery name = "gotoURL" datasource = "# DSN #">
Select adid, URL, CLICK FROM AD
Where adid = '# URL. ADID #'
</Cfquery>
<! --- Clicks plus 1 --->
<Cfset adclick = GOTOURL. CLICK + 1>
<Cfquery datasource = "# DSN #" name = "UPDATECLICK">
UPDATE AD
Set click = '# ADCLICK #'
Where adid = '# URL. ADID #'
</CFQUERY>
<! --- Turn to the ad link address --->
<Cfoutput query = "gotoURL">
<Script language = "JavaScript">
Self. location = '# URL #';
</SCRIPT>
</Cfoutput>
</CFIF>
GAME OVER
This advertisement was changed from ben forta's tutorial. he introduced the idea of how to create ad strips. However, the function is poor and the URL cannot be switched. I can't record the display times and clicks, so I changed it and added some features to it.