Randomizing a Multipage Gallery every 3 days
Posted: Tue Oct 20, 2009 7:50 am
Hi everyone!
I am so close to what I want but just not there yet. Please tell if anyone can help me.
here are some scripts I have found that each have something I want
First:
---------------------------------------------------------------
<?php
// rotate images randomly but w/o dups on same page - format:
// <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
// for second, etc
// (c) 2004 David Pankhurst - use freely, but please leave in my credit
$images=array( // list of files to rotate - add as needed
"bomb.gif",
"frown.gif",
"grim.gif",
"smile.gif" );
$total=count($images);
$secondsFixed=10; // seconds to keep list the same
$seedValue=(int)(time()/$secondsFixed);
srand($seedValue);
for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
{
$r=rand(0,$total-1);
$temp =$images[$i];
$images[$i]=$images[$r];
$images[$r]=$temp;
}
$index=(int)($_GET['i']); // image index passed in
$i=$index%$total; // make sure index always in bounds
$file=$images[$i];
header("Location: $file"); // and pass file reference back
?>
--------------------------------------------------------------
the above script randomizes, but only one type of information - the image. But what I like is that it gives you the ability to customize intervals so that you can keep a randomized array for however long.
Second:
----------------------------------------------------------------
<?php
$content = array(
'http://www.address1.com|image1|Caption 1',
'http://www.address2.com|image2|Caption 2',
'http://www.address3.com|image3|Caption 3',
'http://www.address4.com|image4|Caption 4'
);
shuffle($content);
foreach ($content as $value)
{
$explode = explode('|', $value);
echo '<p><a href="' . $explode[0] . '"><img src="/misc/php/shuffle/' . $explode[1] . '.gif" border="0" width="100" height="25" align="absmiddle"></a> <a href="' . $explode[0] . '">' . $explode[2] . '</a></p>';
}
?>
-----------------------------------------------------------------------
now this script randomizes like I want - multiple types of data that correspond.
This script would be perfect if it had the ability to work with intervals.
Ultimately I would like to have a multi-page gallery (each image having some descriptive text and a separate link) that I can randomize every 3 days or so. I will be forever in your favor ;D
I'm sure the above scripts might come in handy for some.
Andrewiscool
I am so close to what I want but just not there yet. Please tell if anyone can help me.
here are some scripts I have found that each have something I want
First:
---------------------------------------------------------------
<?php
// rotate images randomly but w/o dups on same page - format:
// <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
// for second, etc
// (c) 2004 David Pankhurst - use freely, but please leave in my credit
$images=array( // list of files to rotate - add as needed
"bomb.gif",
"frown.gif",
"grim.gif",
"smile.gif" );
$total=count($images);
$secondsFixed=10; // seconds to keep list the same
$seedValue=(int)(time()/$secondsFixed);
srand($seedValue);
for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
{
$r=rand(0,$total-1);
$temp =$images[$i];
$images[$i]=$images[$r];
$images[$r]=$temp;
}
$index=(int)($_GET['i']); // image index passed in
$i=$index%$total; // make sure index always in bounds
$file=$images[$i];
header("Location: $file"); // and pass file reference back
?>
--------------------------------------------------------------
the above script randomizes, but only one type of information - the image. But what I like is that it gives you the ability to customize intervals so that you can keep a randomized array for however long.
Second:
----------------------------------------------------------------
<?php
$content = array(
'http://www.address1.com|image1|Caption 1',
'http://www.address2.com|image2|Caption 2',
'http://www.address3.com|image3|Caption 3',
'http://www.address4.com|image4|Caption 4'
);
shuffle($content);
foreach ($content as $value)
{
$explode = explode('|', $value);
echo '<p><a href="' . $explode[0] . '"><img src="/misc/php/shuffle/' . $explode[1] . '.gif" border="0" width="100" height="25" align="absmiddle"></a> <a href="' . $explode[0] . '">' . $explode[2] . '</a></p>';
}
?>
-----------------------------------------------------------------------
now this script randomizes like I want - multiple types of data that correspond.
This script would be perfect if it had the ability to work with intervals.
Ultimately I would like to have a multi-page gallery (each image having some descriptive text and a separate link) that I can randomize every 3 days or so. I will be forever in your favor ;D
I'm sure the above scripts might come in handy for some.
Andrewiscool