You are here: Re: Progress indicators on a page...? « PHP Programming Language « IT news, forums, messages
Re: Progress indicators on a page...?

Posted by the DtTvB on 06/23/06 12:40

I have one, without using AJAX.

1. Put this code in the header:
<div id="liveProgress"></div>

2. In your PHP code, add this function:
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').innerHTML = '$x';"
. "</script>";
flush();
}

3. In your loop, type some code like this:
setProgress("Loading... ???%");

Edit message above to whatever you want.

Note that calling too much times of setProgresss function may extremely
slowdown client's browser and eats huge amount of bandwidth. I
recommend to update status every 50-100 loop.

------------------------------------------------
// Example Code:
<html><head><title>Progress Test</title></head><body>
<div id="liveProgress"></div>
<hr /><?php
function setProgress($x) {
echo "<script type=\"text/javascript\">"
. "document.getElementById('liveProgress').innerHTML = '$x';"
. "</script>";
flush();
}
$max = 7;
for ($i = 0; $i < $max; $i ++) {
echo 'Loop #' . ($i + 1) . ' of ' . $max . '<br />';
setProgress('Loading...' . round(($i / $max) * 100) . '%');
sleep(1);
}
setProgress('Finished!!');
?>
</body></html>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация