picture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vietboy
Forum Commoner
Posts: 41
Joined: Mon Dec 01, 2003 10:59 pm

picture

Post 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";
 }

?>
?>
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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...
sanyuan
Forum Newbie
Posts: 10
Joined: Sat Nov 22, 2003 8:55 pm
Location: australia

Post by sanyuan »

Even if you used sleep(), php will still have to print javascript...
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

doh!

Thanks for the correction anyhow :P

-Nay
Vietboy
Forum Commoner
Posts: 41
Joined: Mon Dec 01, 2003 10:59 pm

Post 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.
?>
Hurklefish
Forum Newbie
Posts: 7
Joined: Sat Dec 20, 2003 4:03 pm

a silly possibility

Post 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.
Post Reply