Perhaps you understood what was said. Perhaps not. For clarification . . . .
header() can be used any where in your script as long as no output has been sent to the browser. So, you could run your db query then call header(). Just be sure that nothing is sent to the browser before that. That means the VERY FIRST characters in your PHP file are <? or <?php . No spaces, no carriage returns.