SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Loading Photos Randomly

    Hi all,
    I was hoping someone could help me with some sql, and php...
    I have a site where i want to load images randomly into a page from a database and i want them to be displayed for a specific length of time.

    I already have a script that loads images randomly, but cant find any tutorials on how to keep the photos loaded for a certain lenght of time.

    The php code to show the picture is:

    <img src="showpic.php?user=$user>"

    In showpic.php, i have an sql statement that connects to the database and extracts a random picture using ORDER BY RAND.

    How can i keep that randomly loaded picture loaded for say a day, or a week?
    Thanks,
    Pat

  2. #2
    SitePoint Evangelist spinmaster's Avatar
    Join Date
    Mar 2005
    Posts
    456
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pat2005
    How can i keep that randomly loaded picture loaded for say a day, or a week?
    Hey,
    I think one way to do this might be something like this:

    PHP Code:
    <?php
         
    // get a start and end date from your DB
         
    $query="SELECT date_from, date_to FROM image_date ";
         
    $result mysql_query($query);
         
    $period mysql_fetch_array ($result);

         
    // fetch the current date
         
    $today date('Y-m-d');

          
    // checks for the displaying-period
          
    if($today >= $period["date_from"] && $today <= $period["date_to"]){

            print 
    "CODE FOR DISPLAYING THE PICTURES GO HERE";
          }
    ?>
    This will make sure that your picture will only be displayed during the time between "date_from" and "date_to", which can be as long as you want, a day, a week, ...

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Working!

    Cheers, thats working fine now! I was using CURDATE() to get the current date, and it worked! thanks a mil!


Bookmarks

Posting Permissions

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