Jump to content

Recommended Posts

Hi all, first time here and desperate. I have a host with php enabled so I figure why not use it as folks can turn off javascript.

  I am testing on a wamp windows setup.

What I want to do is output an image or text to a div in a page, pause for 3 seconds then output a new pic or text to overwrite it.

The code I am playing with is this.

<html>

<head><title></title></head>

<body>

<h1>what is this?</font></h1>

<?php

echo '<div id="main"

style="

position: absolute;

top:100;

left: 100;

width: 100px;

height: 70px;

visibility: show;">

my div content is here

</div>';

//for ($x=0;$x<30000;$x++){}

sleep(3);

echo '<div id="main"

style="

position: absolute;

top:100;

left: 100;

width: 100px;

height: 70px;

visibility: show;">

new content now

</div>';

 

?>

 

</body>

</html>

 

Firstly the second text output merges with the  first ! can I destroy a div and then recreate it to get a clear canvas?

BUT the thing I cant do is pause the output, as you see above I have tried an empty counting loop and the sleep function. Neither work as the pause happens before ANY output and then the div shows up with the merged outputs?

  Anyone explain to me how to do this and why does the sleep not occur wher it is placed?

Thanks for your help people.

Link to comment
https://forums.phpfreaks.com/topic/211482-cant-pause-script-output/
Share on other sites

Hi

 

You server sends the details to the web page and then the web page displays them. What you have done is put a delay in the middle of generating the data. To put the delay on the web page would probably be easiest with javascript.

 

All the best

 

Keith

So what you are saying is thet the  browser waits to get the whole page before outputting so that the browser waits whilst php sleeps then gets the rest of the page and outputs it all in one go?

Guess it makes sense when I think of it. If I use one script to output 2 seperate html pages of code , would that work? Gonna try it and see, thanks for your prompt help. :D

Well tried it with following code but does not output 2 seperate pages as I expected, simply merges the divs but the heading is displaced to a lower position?

Guess php is not so easy, probably have to use javascript but like I say folks can turn that off.

<?php 
echo '<html>
<head><title></title></head>
<body>
<h1>what is this?</font></h1>
<div id="main"
style="
position: absolute; 
top:100;
left: 100;
width: 100px;
height: 70px;
visibility: show;">
my div content is here 
</div>
</body>
</html>';

sleep(10);
echo '<html>
<head><title></title></head>
<body>
<h1>what is this?</font></h1>
<div id="main"
style="
position: absolute; 
top:100;
left: 100;
width: 100px;
height: 70px;
visibility: show;">
new contenthere now 
</div>
</body>
</html>';
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.