I would think that you would loop through your query, and build a list.  
For each query record, loop from 1 to the weight value, and add the 
bannerID to the a list called bannerIDList for each nested loop.  This way 
if you have one banner with bannerID=301 and weight=2, and a second 
banner with bannerID=302 and weight=10, the list would look like:

"301,301,302,302,302,302,302,302,302,302,302,302"

Then you could pull a random ID from this list and run the query.

>>> Elizabeth Walter <[EMAIL PROTECTED]> 03/05/02 01:14PM >>>
Hello-

I am developing a banner rotating tool and need some ideas on how to best
handle a requirement.  I have gotten the tool to a point where it displays
banners randomly- no problem.  Now what I need to do is give certain 
banners
more "weight" than others:  some banners need to be displayed more
frequently than the rest.  The code that I have below gives equal weight 
to
each banner; I need to find a way to give some banners more prevalence on
our pages.


        <cfset activeBanners=arrayNew(1)>

        <cfoutput query="qryActive">
                <cfset activeBanners[#qryActive.currentRow#] = "#id#">
        </cfoutput>

        <cfset rows = arrayLen(activeBanners)>

        <cfset randomId = randRange(1,#arrayLen(activeBanners)#)>

        <cfquery datasource="#dsn#" name="qryBanners">
        SELECT 
                i.*, 
                a.advert_name
        FROM 
                images i, advertiser a
        WHERE 
                i.id = #activeBanners[randomId]# and
                i.advert_id = a.advert_id
        </cfquery>


Any ideas?  

Thanks in advance,
Elizabeth


______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to