wutzmanaym Posted March 23, 2007 Share Posted March 23, 2007 A script I'm writing outputs a HTML table with many rows. Each row is the result of a query which takes about one minute to perform. When I run the script in a browser, the page takes several minutes to load and then displays the entire table. Is it possible (using PHP) to display the table as it gets constructed, one row at a time? A page that does this is http://www.b3ta.cr3ation.co.uk/site/music-plus/ but I don't know if it uses PHP for this. Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/ Share on other sites More sharing options...
interpim Posted March 23, 2007 Share Posted March 23, 2007 maybe nest a while statement within a while... have one inside write each line, while the outside while cycle through the database? Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213704 Share on other sites More sharing options...
interpim Posted March 23, 2007 Share Posted March 23, 2007 on second thought... that won't work :/ far as I know, the script will want to finish before it outputs anything to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213707 Share on other sites More sharing options...
janroald Posted March 23, 2007 Share Posted March 23, 2007 Not sure about this, but maybe if you give your table an absolute width, and als each row the same, then the browser might output faster as it doesnt have to recalculate fixed proportions depending on the output. One minute pr row? Damn... You could also try to make each row it's own table. Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213713 Share on other sites More sharing options...
janroald Posted March 23, 2007 Share Posted March 23, 2007 Your script does actually output data after each query, right? Not making one big variable to put out at the end? Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213717 Share on other sites More sharing options...
wutzmanaym Posted March 23, 2007 Author Share Posted March 23, 2007 Your script does actually output data after each query, right? Not making one big variable to put out at the end? Yes, output after each query. I got rid of the table, and just echo the data now, it looks like this: foreach($array as $item) { $result = get_data_for_item($item); // this takes 1 minute echo $result . "<br>"; } But it's still the same as before: If $array has 10 items, the page loads 10 minutes and then displays all results. Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213879 Share on other sites More sharing options...
janroald Posted March 23, 2007 Share Posted March 23, 2007 Did a check and its the same on my server too. Havent really thought too much about this before now, but you got me a bit curious. Seems php does it's work and outputs when its all done. I'm guessing this behaviour can be changed through setting som custom php.ini variables, and will look into it tomorrow some time. Maybe someone else has the solution for you before then. Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213912 Share on other sites More sharing options...
wutzmanaym Posted March 24, 2007 Author Share Posted March 24, 2007 I asked this question on another forum, and someone there knew the solution: Simply call ob_flush() and then flush() in order to push all output that has been produced so far to the client. My code now looks like this and works perfectly foreach($array as $item) { $result = get_data_for_item($item); // this takes 1 minute echo $result . "<br>"; ob_flush(); flush(); } Quote Link to comment https://forums.phpfreaks.com/topic/44016-solved-displaying-parts-of-a-page-while-the-page-is-not-complete-yet/#findComment-213970 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.