shawntbanks
Programmer
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>
<!--- 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>