Jump to content

Delaying


turbocueca

Recommended Posts

use sleep:
[code]<?php

sleep(1);
echo "hello";

?>[/code]After one secound hello should appear. NOTE if you have a series of sleep functions ie:
[code]<?php

sleep(1);
echo "hello";

sleep(2);
echo "hello";

sleep(3);
echo "hello";

?>[/code]Nothing will be outputted for at least 6 secounds as the sleep functions add up to the total time php sleeps for. It will not show the first hello after 1 secound then the secound hello after two more secound and the last hello after three more secounds. it will show hellohellohello after 6 secounds has passed
Link to comment
Share on other sites

Here's a sample script to list data items at 1 second intervals

[code]<?php
     // php data - could be from database
  $item = array('Widget', 'Gizmo', 'Grommit', 'Wotsit');
?>
<HTML>
<HEAD>
<meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)">
<title>Sample delay script</title>
<meta Name="author" content="Barand">
<script LANGUAGE="javascript">

<?php
     // put php data into js array
  echo "var jsitems = new Array(";
  echo '"' . join('","', $item) . '");';
  echo "\n\n";
    //
  echo "var count = 0;\n\n";
?>

function displayItem() {
         var elem = document.getElementById("items");
         elem.innerHTML = elem.innerHTML + "<BR>" + jsitems[count];
         count++;
         if (count < jsitems.length) setTimeout("displayItem()", 1000);
}

</SCRIPT>
</HEAD>
<BODY onload='setTimeout("displayItem()", 1000);'>

Here are the items<br><br>
<DIV id='items' style="margin-left:50px; padding:10px; border: 1px solid silver; width: 200px; height:200px">
</DIV>

</BODY>
</HTML>[/code]

hope it helps
Link to comment
Share on other sites

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.