SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    0 Post(s)
    0 Thread(s)

    Synchronized Random Image Rotator HELP!

    I need a script that loads a two part image. An example of this is shown at the following site:

    The banner and the top bar consist of two images in two table cells and despite it being randomized (click refresh to see another banner), the top bar syncs with the banner image.

    So though randomized, when topbar_1.jpg is loaded, banner_1.jpg is also loaded. If topbar_2.jpg is loaded, banner_3.jpg is also loaded.

    When viewing the source of the site, it did not show any type of Javascript code, so I am assuming that this can be done with php. Maybe 2 arrays of images and storing them into two variables that are synced with each other maybe? I would really need this script and would appreciate it if anyone could help me out as I have no experience in PHP coding.

    The following are a few links with topics from various forums of conceptually what I want to have done, but cannot find the solution:
    Last edited by Terra812; Feb 21, 2006 at 07:35. Reason: Change the topic.

  2. #2
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    0 Post(s)
    0 Thread(s)
    Hi there

    here's the basic idea of how I may do this... I must warn you though, I'm a little out of it, but eh... here goes.

    The simplest way is often the best. Why use PHP to randomise it, when you can retrieve random results from the datasource?

    I would build a table with the following fields:

    idads - int auto increment primary key
    link - varchar(250) or TEXT
    topbar - varchar(250)
    banner - varchar(250)

    populate your table like so:

    idads | link | topbar | banner |
    1	  | | topbar1.jpg | banner.jpg |
    2	  | | somejpegfile.jpg | somebanner.jpg |
    3	  | | anotherjpegfile.jpg | anotherbanner.jpg |
    so with your table looking like so, you could get a result by using the rand() SQL function.

    here's the SQL:
    SELECT link, topbar, banner 
    FROM rotatingads
    ORDER BY rand()
    LIMIT 1


  3. #3
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    0 Post(s)
    0 Thread(s)
    Are you asking something like this ?
    PHP Code:
    $images1[] = 'img/1.jpg';
    $images1[] = 'img/2.jpg';
    $images1[] = 'img/3.jpg';
    $images1[] = 'img/4.jpg';
    $images1[] = 'img/5.jpg';
    //you can add as many images as you want, then,
    $images2[] = 'img/10.jpg';
    $images2[] = 'img/20.jpg';
    $images2[] = 'img/30.jpg';
    $images2[] = 'img/40.jpg';
    $images2[] = 'img/50.jpg';
    //add the same number of images as images1
    //and you can keep adding $images3, $images4, etc. Now,

    srand ((double) microtime() * 1000000);
    $random_number rand(0,count($images1)-1);

    In this way, each time the browser will load, you will get a new image, which itself consists of two parts which are inter-related. Just take care that 1.jpg relates to 10.jpg and so on ... rest will be fine. Hope I've understood the question ...


Posting Permissions

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