You have options,
I think a good options is to put a div in, and use CSS to make the style:
.mydiv
{
display:none;
}
<div class="mydiv">(query results)</div>
Put this div in the very very bottom of the page, right before </body>.
Absolute position this div at 0,0 with 100% width and height ( no margin ).
Remember it will not be visible or take up space because of the stylesheet.
Inside this div, the output should be generated, and after the input generation is complete, it should have javascript to set the div display mode to 'block'.
So, the flow of the code would be:
1) output page with 'please wait' text
2) flush();
3) process query and put results inside div
4) javascript makes div visible
5) flush();
all from the same php script, all at the same time.
you may want to toss in a sleep(1); and another flush(); after the first flush(); for good measure
Because the div is processed and filled last, the restof of the page will be visible using the flush();
Another option is to hammer the output buffer.
Problems with this approach?
The main 2 problems are:
1) some browsers may not support the javascript required for making the div visible. Your layout has to be well planned, a lot of browsers will not display content until the rest of the element is complete, this usually does not include the body or html tags.
2) Because you are essentually making 2 complete pages inside one, the page size can become very very large. Try to keep graphics and layout to a minimum, and limit query results to a few hundred.
Another option would be to the php write to a file the output that would go into the DIV, and load that when complete ( cuold be setup as a cache of queries that have already been run in the last X minutes, etc, and really be tuned into a fine machine.
There are more ways to do this I am sure. I am not sure if my 2 examples are the best.