You can send Status: 20x (x is 1 or 2 or something - not sure) to let browser know that nothing has change and no page reload is needed.
This way, combined with <meta name="refresh"...>, you can set browser to call the script (for example) chk.php every 5 seconds. Then, chk.php will check if the query is done (i.e. result was outputed to the file). If it's done, it sends you the result (or heard("Location: script-that-sends-result.php")😉. If it's not done, header("Status: 20x"); (check value of x at the page I've sent you)
If you're fine with JavaScript, the onLoad="" solution might be better, depending on what makes your query slow enough for this:
1. query takes lot of time (consider optimizing it)
2. query has big output which takes a lot of time to load (this definitely requires eloy's solution)