I have a table whose structure is something similar to this
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
I want to be able to use PHP's flush function to print out columns by columns as the data is coming out. So in this example I want it to print First Name, Jill, Eve, and then second column; Last name Smith; Jackon, and so on and so forth.
I don't want to wait until the data is loaded (the script takes a while and the whole point is to have it echo out while its running) and I don't want to deal with AJAX.
The only thing I could think of was using a bunch of go to's (I know thats a terrible implementation). Anyone have any thoughts?
I think I came up with a pretty innovative solution. It does use ONE line of javascript, but it basically is just a manual AJAX process in PHP.
So right now I had one file that was running and as it was running it was outputting a table as the PHP page ran. What I did was break that up into TWO files. This example is how you can basically erase the page (or an element on the page and reload it). So you'll have page one
<?php
$i=0;
while($i<100){
echo (file_get_contents("http://192.241.240.69/hakre/page2.php?var=$i"));
flush();
ob_flush();
usleep(200000);
$i++;
}
This calls to page 2 which has a javascript erase page function (could be erase a single element and reload it with the updated content (see page two code below)
<?php
$var = $_GET['var'];
echo '<script type="text/javascript">'."document.body.innerHTML = ''".'</script>';
echo $var;
?>
The result would be http://192.241.240.69/hakre/page1.php - not the sexiest solution but it does use pretty much only one line of javascript and almost all PHP in conjunction with the flush function. Here is an example writing a page column by column http://192.241.240.69/hakre/Table.php