Revolving Images
Hi
I have written a script (see below) that picks a random flash animation from a mysql database with PHP. I want the script to repeat after the animation is loaded and replace it with another random animation. This is to happen indefinitely as I want the flash animations to revolve once each one is loaded. Can anyone suggest the PHP code needed in order to indefinitely execute the code below over and over again - replacing the previos image each time?
Many thanks
<?php
mysql_connect("localhost","xxx","xxx");
$i = 0;
$query="select * from artists where Banner = '1'";
$result=mysql_db_query("cmlwebd_xsp",$query);
while($row=mysql_fetch_row($result))
{ $i = $i+1;
$current = $row[0];
$banner[$i] = $current;
} $new = rand(1, $i);
$number = $banner[$new];
mysql_free_result($result);
?>
<?php
mysql_connect("localhost","xxx","xxx");
$query="select * from artists where ID = $number";
$result=mysql_db_query("cmlwebd_xsp",$query);
while($row=mysql_fetch_row($result))
{ ?>
<div align="center">
<embed SRC="<?php print($row[5]);?>" WIDTH="280" HEIGHT="230" PLAY="true" LOOP="false" QUALITY="best" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><br><a class="artistmenu" target="_parent" href="artistprofile.php?ID=<?php print($row[0]);?>"><?php print($row[3]);?> - Click to view artist profile</a></div>
<?php } mysql_free_result($result);
?>
Greg K posted this at 00:04 — 30th March 2006.
He has: 2,145 posts
Joined: Nov 2003
The problem is PHP is processed on the server, you are wanting something that works on the client side.
You would still use PHP to get a list of available images, and store that say in a javascript array.
-Greg
ChrisL posted this at 10:06 — 30th March 2006.
They have: 68 posts
Joined: Dec 2005
I can manage to get the flash .swf files into a javascript array, yes, but can anyone suggest the code needed in order to create a revolving image from that array which will replace the previos image each time on a time delay?
I have managed to do this with image files (see the code below) butit does not work when I use .swf files. I have no idea why, I thought the principle would be the same?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script LANGUAGE="JavaScript">
<!-- Begin
var interval = 2.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("xxx/new/xsp/artists/5thavenue/images/artist.gif");
image_list[image_index++] = new imageItem("xxx/new/xsp/artists/Abbashow/images/artist.jpg");
image_list[image_index++] = new imageItem("xxx/new/xsp/artists/Allaidhmodahn/images/artist.jpg");
image_list[image_index++] = new imageItem("xxx/new/xsp/artists/Beagles/images/artist.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}
// End -->
</script>
</head>
<BODY OnLoad="rotateImage('rImage')">
<center>
<img name="rImage" src="xxx/new/xsp/artists/5thavenue/images/artist.gif" width=280 height=230>
</center>
<p>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center></p>
</body>
</html>
gretty posted this at 03:28 — 2nd April 2006.
They have: 9 posts
Joined: Apr 2006
yes use php
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.