Your question is a common one in web development. I highly recommend learning how to use Zend Framework. Even if you choose to not use the framework for any real projects, the things that you learn will significantly improve your knowledge of PHP and give you a much better understanding of how to deal with problems such as the one posed by your question.