#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Displaying ad in the form using RandRange


    I have 3 images(Ads) which should be distributed 33%, 33% and 34% (100%)
    The images should be displayed one after the other in the form.

    Could anyone help me how to place the ad in my coldfusion form page.

    something could be like
    <cfset random = RandRange(33, 100)>

    <cfif random eq 34>
    <iframe ....> src1</iframe>
    <cfelseif random eq 33>
    <iframe ....> src2</iframe>
    <cfelseif random eq 33> -------?
    <iframe ....> src3</iframe>
    </cfif>

    when user clicks the form each time the image(ad) also should change each time.

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    Hardcoding these is very limiting, since any time you add more, remove some, or change the image url you have to change the code. I'd put them in a database and select and just query for a random image.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0
    Thanks for your reply.

    I'm told not to use Database for this purpose.

    I tried to use <cfset random = RandRange(1,3)>
    <cfif random is "1">
    <iframe> ...</iframe>
    <Cfelseif random is "2">
    <iframe>...</iframe>
    <cfelseif random is "3>
    <iframe>...</iframe>
    </cfif>

    From the above statement - it works well, but often the images repeating 2 or 3 times which I want to avoid. Instead of RandRange is there any method(way) which possible to display images one after the other continuously like looping for each click?

    Thanks!


    Originally Posted by kiteless
    Hardcoding these is very limiting, since any time you add more, remove some, or change the image url you have to change the code. I'd put them in a database and select and just query for a random image.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    If you don't actually want it random and want it to be sequential, sure. Just set up an application-scope variable that starts at 1, and increment it each time the page loads. When it gets to 3 and runs the third image, set it back to 1 so the count starts over.

IMN logo majestic logo threadwatch logo seochat tools logo