SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Loading Photos Randomly
-
Apr 5, 2005, 02:27 #1
- Join Date
- Mar 2005
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Apr 5, 2005, 08:20 #2
Originally Posted by pat2005
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";
}
?>
-
Apr 5, 2005, 10:25 #3
- Join Date
- Mar 2005
- Posts
- 14
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Working!
Cheers, thats working fine now! I was using CURDATE() to get the current date, and it worked! thanks a mil!
Bookmarks