page 1
doctype, html, head, body...
<a href="display.php">Show dynamic stuff</a>
<a href="download.php">Download dynamic stuff</a>
/body & html
display.php
$stuff = somehowGetDynamicStuff();
header('content-type: text/html');
echo $stuff;
download.php
$stuff = somehowGetDynamicStuff(); // same function as above
header('content-type: application/octet-stream; name=file.html');
header('content-disposition: attachment; filename=file.html');
echo $stuff;
There is no difference whatsoever in how you get the data to the browser. The only thing that decides if the browser shows it (and how) or if it prompts the user for download/open with application..., is the content-type header.
So I don't know if you need to "select", even though I assume that by that you mean issue a select query to a database. You might read an xml file, scrape the web, echo the result of time() or show the current outdoors temperature.
Why your dynamic content is not shown is a php issue and is resolved through regular debugging. Turn on error logging/reporting etc. And while you do so, you may wish to use content-type text/plain or text/html so you can see the results in the browser directly without being prompted for what to do all the time.
And if you are using IE8, there's a chance that it will disregard your content-type for no good reason, and the solution is to add
header('x-content-type-options: nosniff');
If my memory serves me right. It was brad who made me aware of this proprietary IE8 header in one of the clientside technologies threads.