Jump to content


Photo

Delaying


  • Please log in to reply
7 replies to this topic

#1 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 17 March 2006 - 09:55 PM

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 10:01 PM

What problem are you trying to solve?

Ken

#3 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 17 March 2006 - 10:17 PM

I want a text to appear on the display in 1 second, instead of instantly appearing.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 March 2006 - 10:23 PM

use sleep:
<?php

sleep(1);
echo "hello";

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

sleep(1);
echo "hello";

sleep(2);
echo "hello";

sleep(3);
echo "hello";

?>
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

#5 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 17 March 2006 - 10:48 PM

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?

#6 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 17 March 2006 - 11:07 PM

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

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 18 March 2006 - 10:45 AM

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

<?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>

hope it helps
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 18 March 2006 - 02:01 PM

thanks i'll check it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users