Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Random Banner

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lake Forest, CA
    Posts
    259
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Banner

    Hey Everyone...

    Lets say that I have 8 banners in my database...

    And I want to display 4 at a time.

    How can I randomly select 4 from the database?

    Thanks!!
    The Wizzard
    OC Motor Cars | OC Auto Sports (Coming Soon!)

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Well, as for selecting 8 banners out of a database you will need to assign an ID number to them. 1-8.

    Here is the randomizing code for the numbers you have, so only 4 will show, and to make it alot easier for you, the 4 numbers are all different so you don't see the same banner twice.

    Work with this, this is the only hard part in making what you need. It will help you in ASP to figure out the rest for yourself. But still ask questions if you don't understand.

    Code:
    <%
    
    Dim IntRandom(3), I, J
    
    Randomize
    
    For I = 0 To 3
      
      IntRandom(I) = Int(8 * Rnd() + 1)
    
      For J = 0 To 3
    
      If IntRandom(I) = IntRandom(J) And IntRandom(I) <> 0 And I <> J Then
        I = I - 1
        Exit For
      End If
    
      Next
    
    Next
    
    For I = 0 To 3
      Response.Write IntRandom(I) & "<br>"
    Next
    
    %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •