is there a way to pause a while loop and display a message on each iteration?
| SitePoint Sponsor |



is there a way to pause a while loop and display a message on each iteration?


There is a sleep function in which you can pause number of seconds you specified.



Thanks, but there's no opportunity to display a message. I'm on to rendering javascript in php.
This displays nicely, but there's no var in it:
how do I get the php variable into the JS var when the JS is rendered in php?Code:<?php echo '<script type="text/javascript">'; echo 'alert("Hello World")'; echo '</script>'; ?>
Code:$str = "Hello World"; echo '<script type="text/javascript">'; echo 'var str = ?????'; echo 'alert(str)'; echo '</script>';


Or:PHP Code:$str = "Hello World";
echo '<script type="text/javascript">';
echo 'alert("' . $str . '");';
echo '</script>';
PHP Code:$str = "Hello World";
echo '<script type="text/javascript">';
echo 'var str = "' . $str . '";';
echo 'alert(str);';
echo '</script>';



Thanks kduv. That fits the bill!.
This is one for my topic scrapbook. This one is truly a keeper! I've been needing something like this for years. Before recently, I didn't understand javascript well enough to even ask this question.
Another way in JS:
The setTimeout() method will run the callback function hideMessage() after 4000 miliseconds. You could use AJAX to post to a PHP page in the callback if you wanted.Code:displayMessage(data); setTimeout(function(){hideMessage();}, 4000);
Steve
Bookmarks