I'm trying to use the following script to output a list of directories. I'm expecting the script to print out the directories one by one in browser. However, it will just waiting for the server for long time, and then out put all the records in one time. What's wrong with the script? I need to watch on the browser and the script prints out the directories one by one instead of waiting for long time and print out in one time. BTW, I tried out bufferring without success. <html> ... <body> <?php ... //Around 500 records in $rs $rs = mysql_query("SELECT id name url pr remarks FROM free_dirs"); while(list($id, $name, $url, $pr, $remarks) = mysql_fetch_array($rs)){ //do something here takes around 15 seconds echo "<table width=\"800\">"; if($id%2==0) echo "<tr bgcolor=\"#fef8ed\">"; else echo "<tr bgcolor=\"#d7ef9c\">"; echo "<td>$id</td>"; echo "<td><a href=\"$url\" target=\"_blank\"> $name</a></td>"; echo "<td>$pr</td>"; echo "<td>$remarks</td>"; } ... ?> </body> </html> PHP:
Could it be a simple html issue that your browser is having trouble rendering the page? I see you have no close tr or close table being output. Also, your open table is inside the loop. So you are opening 500 tables, closing none and closing no rows. Try just outputting a bulleted list at first and see if it displays quickly, then work on your html issues.
You cannot fully control it..it depends on lot of things..php output buffering..turn it off from php ini..unfortunately even if you do that..many browsers do a buffering of there own..so you cant be 100% sure it will print line by line..still use ob clean and ob flush..along with fflush
Uhm... HTML is not asynchronous - you put in a command (say a PHP-script) and it renders the page when the sript is done. Simple as that. If you want to see each line show up one by one as they're fetched from the database, you need to add an AJAX-query, or reload the page for each line (each record) you process. Elsewise it'll output the complete list when it's done, simple as that.
you need to generate one static page one time and use that static page to display. 1.) run your script to save the whole html code (with the listings) to static.html 2.) mainpage.php will include(static.html); 3.) viola no need to stress the server and wait how long it'll take to finish the loading process