Coldfusion MX ad rotation System production tutorial _coldfusion

Source: Internet
Author: User
Tags dsn
Wait Blue Ideal
CF doesn't offer an ad component like ASP, but this does not mean that can not make a powerful advertising system, where I put on a simple ad rotation system, but also I CCF forum for the use of. function, there are display times and clicks. It is easier to expand on this basis, and it can be sorted and displayed, The following code just shows the big banner. Just want to make a comment, everybody extrapolate, can produce the function more powerful advertisement system comes out.

<!---to determine whether there are address delivery--->
<cfif not isdefined ("URL. Adid ") >
<!---default to display ads--->
<cflock timeout= "Ten" >

<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 advertising--->
<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 there are passed parameters--->
<cfquery name= "Gotourl" datasource= "#DSN #" >
SELECT Adid,url,click from AD
WHERE adid= ' #URL. adid# '
</cfquery>

<!---click Number plus 1--->
<cfset Adclick=gotourl. Click+1>

<cfquery datasource= "#DSN #" Name= "Updateclick" >
UPDATE AD
SET click= ' #ADCLICK # '
WHERE adid= ' #URL. adid# '
</CFQUERY>

<!---turn to advertising link address--->
<cfoutput query= "Gotourl" >
<script language= "JavaScript" >
Self.location = ' #URL # ';
</SCRIPT>
</cfoutput>
</CFIF>



Code Copy Box
The following is a reference fragment:

<!---to determine whether there are address delivery--->
<cfif not isdefined ("URL. Adid ") >
<!---default to display ads--->
<cflock timeout= "Ten" >

<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 advertising--->
<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 there are passed parameters--->
<cfquery name= "Gotourl" datasource= "#DSN #" >
SELECT Adid,url,click from AD
WHERE adid= ' #URL. adid# '
</cfquery>

<!---click Number plus 1--->
<cfset Adclick=gotourl. Click+1>

<cfquery datasource= "#DSN #" Name= "Updateclick" >
UPDATE AD
SET click= ' #ADCLICK # '
WHERE adid= ' #URL. adid# '
</CFQUERY>

<!---turn to advertising link address--->
<cfoutput query= "Gotourl" >
<script language= "JavaScript" >
Self.location = ' #URL # ';
</SCRIPT>
</cfoutput>
</CFIF>



GAME over
This ad was changed from Ben Forta's tutorial. He introduced the principle of advertising strip production is similar, but the function of the poor, can not be a URL to turn. The number of times and clicks cannot be recorded, so I changed him and added some features to it.


Principle: Put the advertising data in a database table, extract all the advertising number (ID), the ID stored in a application variable inside, I show a, from this application variable inside the display of the ad ID, The banner will not be displayed next time. Until all the banners have been shown, if the application variable is empty, requery the database, and then fetch all of the ad IDs,,, keep going.


Hint: Save a file to your own database line. Display ads, the advertising bar URL to turn in this file.

Notice this variable: application.ad, this is an application variable, I define it as a string, in the CF string it can be application.ad= "I ' m wait" can be application.ad= "1 2 3 4 5 6 7 9 ", I'm using this ad in the back.
Again, this analogy: for example, I was on my first visit. Call application.ad= "1" and then delete this application.ad= "1" Next time Only: Application.ad= "2 3 4 5 6 7 9" One Less, This results in a rotational effect. Of course, all the time until the full display, and then requery the database, extract all advertising IDs. Put it in the Application.ad string.
Take a look at this sentence:
<cfif Listlen (application.ad) EQ 0>

It means: If I have this application.ad length of 0, I requery the database and put the query results in the APPLICATION.AD variable. Note that. To test the length of a list, you cannot use Len (), but rather a function that tests the length of the list specifically Listlen
<cfquery name= "GetID" datasource= "#DSN #" >
Select Adid from AD
</cfquery>

<cfset application.ad = valuelist (Getid.adid) >

If, if there is no end to show a rotation, it is certainly not equal to 0, then the database will not be requery.

As for getting the first character, you can use
<cfset Thisadid = Listgetat (application.ad, 1) >
And then delete this. Next time it's your turn.
<cfset application.ad = Listdeleteat (application.ad, 1) >

The point is these, as for the following updates show the number of times, and count the number of times, are ordinary 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.