Page 1 of 1

picture

Posted: Sat Dec 20, 2003 3:40 am
by Vietboy
This is just a random picture. How would I write to set it show the next picture in 10 seconds after it's view without reloading the page?

Code: Select all

<?php

$pix=rand(1,5);

if($pix==1)
  {
    echo "<img src='image.jpg' alt='text'>";
    echo "Text";

  }
else if($pix==2)
  {
   echo "<img src='image2.jpg'>";
echo "Text";  
}
else if($pix==3)
  {
   echo "<img src='image3.jpg'>";
echo "Text";  
}

else if($pix==4)
 {
   echo "<img src='image4.jpg'>";
echo "Text"; 
}

else if($pix==5)
 {
   echo "<img src='image5.jpg'>";
echo "Text";
 }

?>
?>

Posted: Sat Dec 20, 2003 3:50 am
by aquila125
PHP is server side.. so it's not possible...

You can do it with javascript... I don't know the exact code, but I know it's pretty easy to change the source of an image to a new one. (you can save the images in a javascript array and have js select one randomly)

Posted: Sat Dec 20, 2003 4:10 am
by Nay
It's possible, but not recommended. Take a look at sleep()

/me thinks sleep() is the function, correct me if i'm wrong...

-Nay

Posted: Sat Dec 20, 2003 4:44 am
by aquila125
No it's not :)

Sleep just delays the script execution, but you can not change anything on the client side through PHP...
PHP generates HTML and that is sent to the client...

Posted: Sat Dec 20, 2003 4:44 am
by sanyuan
Even if you used sleep(), php will still have to print javascript...

Posted: Sat Dec 20, 2003 5:16 am
by Nay
doh!

Thanks for the correction anyhow :P

-Nay

Posted: Sat Dec 20, 2003 11:37 pm
by Vietboy
Hmm.. If that is not possible.

What about I set a URL of pictures image then with a link to click on and it will show that picture.. Click again to show the next picture.
?>

a silly possibility

Posted: Sun Dec 21, 2003 1:45 am
by Hurklefish
ok, this may not work at all for your purposes. If you want to display a series of images without using any client side script, there's a chance you could use an animated gif, with each frame being a different image, and a 10 second delay between frames. JASC's animation shop (comes with paint shop pro) has tools that will let you do this, I've had good success with it.