turbocueca Posted March 17, 2006 Share Posted March 17, 2006 Hello friendly people, I want to know how can I add a delay time to a instruction to be executed. Can someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/ Share on other sites More sharing options...
kenrbnsn Posted March 17, 2006 Share Posted March 17, 2006 What problem are you trying to solve?Ken Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18431 Share on other sites More sharing options...
turbocueca Posted March 17, 2006 Author Share Posted March 17, 2006 I want a text to appear on the display in 1 second, instead of instantly appearing. Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18437 Share on other sites More sharing options...
wildteen88 Posted March 17, 2006 Share Posted March 17, 2006 use sleep:[code]<?phpsleep(1);echo "hello";?>[/code]After one secound hello should appear. NOTE if you have a series of sleep functions ie:[code]<?phpsleep(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 Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18441 Share on other sites More sharing options...
turbocueca Posted March 17, 2006 Author Share Posted March 17, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18454 Share on other sites More sharing options...
turbocueca Posted March 17, 2006 Author Share Posted March 17, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18459 Share on other sites More sharing options...
Barand Posted March 18, 2006 Share Posted March 18, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18534 Share on other sites More sharing options...
turbocueca Posted March 18, 2006 Author Share Posted March 18, 2006 thanks i'll check it Quote Link to comment https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.