The other Sam has already explained things well but perhaps a little clarification will help.
The way that PHP works is that the compiler reads the PHP file from beginning to end. It generally writes the HTML out as-is and processes the PHP code when it is encountered. Whatever HTML is generated by the PHP code is written and the compiler proceeds from there. It is not clear what you need to do but you just need to figure out a different design depending on what you need to do.