Revert "Revert "put entire select statement inside php section""

This reverts commit 007c83ef8439898234c86fc08abd5bbae06e9834.