Coldfusion MX advertising rotation system production tutorial

Source: Internet
Author: User

Wait blue ideal
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>

Code copy box
The following is a reference clip:

<! --- 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.

Principle: put AD data in a database table, extract all ad numbers (IDS) at a time, and store this ID in an APPLICATION variable. I will display one, delete the displayed ad ID from the APPLICATION variable. The ad ID will not be displayed next time. if the APPLICATION variable is empty, query the database again and retrieve all advertisement IDs until all advertisement entries are displayed.

Tip: Change the saved file to your own database. The advertisement is displayed, and the advertisement URL is redirected to the file.

Please note this variable: Application. AD: This is an Application variable. I define it as a string. In the CF string, the Application can be used like this. AD = "I'm wait" can also be applied. AD = "1 2 3 4 5 6 7 9", I use
Let's talk about this metaphor: for example, it was my first visit. call Application. AD = "1" and then delete this Application. AD = "1" is left next time: Application. AD = "2 3 4 5 6 7 9" one less at a time, this achieves the rotation effect. of course, until all are displayed, re-query the database and extract all advertisement IDs. put it in Application. AD string
Note:
<CFIF ListLen (Application. AD) EQ 0>

If I use this Application. if the AD length is 0, re-query the database and place the query result in Application. in the AD variable. note. the length of the list to be tested cannot be LEN (). Instead, the ListLen function is used to test the list length.
<Cfquery name = "getID" datasource = "# DSN #">
Select adid from ad
</Cfquery>

<CFSET Application. AD = ValueList (getID. ADID)>

If there is still a rotation not displayed, it is definitely not equal to 0, then the database will not be re-queried.

To obtain the first character, you can use
<CFSET ThisAdID = ListGetAt (Application. AD, 1)>
Then delete this file. Next time it will be the next time.
<CFSET Application. AD = ListDeleteAt (Application. AD, 1)>

The focus is on this. the following update display times and Count display times are common CF code. Nothing special.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.