Display a text at different time intervals

Hello everyone, I am trying to display records from a Database 1 by 1 at different time intervals. Can anyone please help.
I have a table NAME with field fname: Tom, Web, PHP.

I want to echo Each fname at different time intervals. that is if Tom apppears first then Web will appear after 3 seconds then PHP appears after 8 seconds. I have tried using setTimeout() but it is not working

cant be done in php, php processing only occurs on the host server.
3/8 secs is short
you will probably be looking at javascript/jquery routines

Post removed

You can add a delay using jQury. For this you would have different Divs for each text and use the delay properties

[php]

div { position: absolute; width: 60px; height: 60px; float: left; } .first { background-color: #3f3; left: 0;} .second { background-color: #33f; left: 80px;}

Run

[/php]

See the tutorial here: http://api.jquery.com/delay/

if you are just trying to set intervals you can do this with php there is a php function called “sleep”, and if you would like to make it work with portions of a second you can use the php function “usleep”

sleep(3) would pause the script for 3 seconds then continue

usleep(3500000) would pause the script for 3 and a half seconds then continue
you could use a while loop and have it echo out each record then pause then echo another record etc.

example:
[php]
$result = mysql_query(“SELECT * FROM table”);
while ($res=mysql_fetch_assoc($result)) {
echo $res[‘field’];
sleep(3);
flush();
}
[/php]

I believe this would give the effect that you are looking for without resorting to javascript. Although javascript would be the much prettier way of doing it.
If I remember correctly the php sleep function might have the browser page looking as though it is loading the entire time, while javascript will actually look like the page completely stopped loading then it will reload when the pause has ended.

setTimeout function is javascript and not php

not really, as the page isnt sent as it is generated, but when the script completes.
adding sleep/usleep will pause the script, but also no output to the client is sent during this time.

wow I stand corrected :wink:
I tried to flush it out, but I guess with php it does have to wait until the whole script is executed until it will display results! so Javascript is the answer.

Sponsor our Newsletter | Privacy Policy | Terms of Service