Im building an application with PHP, similar to any CMS we have(wordpress, joomla), not such big one, but just my custom script to manage some blogging requirements, so what I do is, I do generate complete URL in SEO friendly manner like
www.domain.com/category1/category2/category3/page/
I can do this by joining relations from Page to domain all the way like
page->category3->category2->category1->domain
I did this but I feel i am overloading the server and some how I feel my code is in efficient, in the way, I need to execute 3 queries to get this page hierarchy, for fetching all 3 categories addresses(slugs), so I am looking is there any efficient way to achieve the same in better manner?