faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 19 people (74%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Is there anyway I can display a progressbar in PHP while i'm in a loop?

Jul 29th, 2001 07:01
Jacq, j chua, http://www.sepulchre.co.uk/article.php?cat=9&index=9


Make initial html page and then flush it to the client. Use Javascript 
to increase the bar....


Like this:

<html>
	<head>
		<title>Progress Bar</title>
	</head>
	<body>
		<img name="pb" src="/images/gdot.gif" height="10" 
width="1" />
	</body>
</html>
<?
	flush();
	$i = 1;
	while ($i < 100)
	{
		sleep(1);			// Do some work here...
		
		// increase the progress bar
		echo "<script language=\"javascript\">";
		echo "window.document.images('pb').width = 
$i;</script>";
		flush();
		$i += 10;
	}
?>