Jump to content

Archived

This topic is now archived and is closed to further replies.

turbocueca

Delaying

Recommended Posts

Hello friendly people, I want to know how can I add a delay time to a instruction to be executed. Can someone help me?

Share this post


Link to post
Share on other sites
What problem are you trying to solve?

Ken

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
With this code the page takes the number of seconds I want to open. How can I make it open instantly, displaying some text, and then wait 1 or 2 seconds to display more text?

Share this post


Link to post
Share on other sites
another problem, I'm trying to output something from a mysql database, but the output isn't what I want, it is this: "Resource id #3"

SORRY - PROBLEM SOLVED

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.