Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to rotate a banner ad

Status
Not open for further replies.

shawntbanks

Programmer
Oct 29, 2003
48
0
0
CA
This is the code that I have to rotate the banners now, but it only does so when I hit refresh, what I want to do is to rotate them while the page displays. (I am assuming that I will have to use javascript to do so) but I would like to use the exsiting code with it. This code pulls the banners from a database and counts the clicks and views and there is also a component that allows me to say how often that it will appear.

<!--- Start Query Banner DB --->
<cfquery datasource="#Database.DSN#" name="banner">
select *
from banners
order by ID desc
</cfquery>
<!--- End Query Banner DB --->

<!--- Start Weighting and Rand Num. --->
<!--- This starts your list for all the numbers to pick from --->
<cfset prodlist="">
<!--- Telling it to output the data your queried --->
<cfoutput query="banner">
<!--- Creating a counter --->
<cfset x=1>
<!--- Starting the loop --->
<cfloop index="x" from="1" to="#banner_weight#">
<!--- This added the banner ID to the list for every weight --->
<cfset prodlist=listappend(prodlist,#id#)>
<!--- Adding one to the counter --->
<cfset x=x+1>
<!--- The end of the looping --->
</cfloop>
<!--- End of the data query --->
</cfoutput>
<!--- This startment pulls a random number from 1 to the length of the list --->
<cfset magicnumb=randrange(1,listlen(prodlist))>
<!--- This one will pull the banner ID out from the random number point --->
<cfset magicnum=listgetat(prodlist,magicnumb)>
<!--- End Weighting and Rand Num. --->

<!--- This queries the specific banner --->
<cfquery datasource="#Database.DSN#" name="views">
select *
from banners
where id = #magicnum#
</cfquery>
<!--- start Adds 1 to view --->
<cfoutput query="views">
<CFSET add = #banner_views# + 1>
<CFQUERY datasource="#Database.DSN#" name="UpdateView">
UPDATE Banners Set banner_views = #add# where ID = #id#
</cfquery>
</cfoutput>
<!--- End Adds 1 to view --->


This is the output for the banners
<cfoutput query="views">
<A HREF="redirect.cfm?ID=#magicnum#" TARGET="_blank">
<IMG SRC="banner_ads/#banner_pic#" alt="#banner_alt#" width="468" height="60" border="0"></A>
</cfoutput>
 
How about putting this as it's own page in an iframe and using javascript or meta refresh to refresh only that frame. The rest of the page remains untouched.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top