pretty urls + ugly database design

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

pretty urls + ugly database design

Post by Luke »

Alright... this is another issue with a terribly designed database schema... just looking for some advice. I am using pretty urls in a directory I am building, but I have to use the category names as my where clause because categories don't have ids in the terrible schema. So... I am using the function I found in scottay's thread about pretty urls...

Code: Select all

static public function cleanUrl($url) {
	   return
		  preg_replace('/[^a-z0-9-]/','',
		  preg_replace('/\s{1,}/','-',
		  preg_replace('/&/',' and ',
		  strtolower($url)
	   )));
	}
This works exactly how I would like it to... but the problem now is that I can't search my database for a category like "health-foods-and-servicesnutritional-products" when in the database it's called "Health Foods & Services/Nutritional Products". Would it be a better idea to create an extra column in the table with the url-safe version of the category to search in... or should I just create a function that matches the url-safe category names to the ones in the database... or am I going about this wrong all-together?
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post by speedy33417 »

Not that my opinion should count too much, since I'm very new to php, but I was dealing with a similar issue just the other day.
I decided to add an extra column and make my life a lot easier. I don't think I'm losing a lot of space on my hosting because of it, but I feel more relaxed coding this way.

Hope this helps. Good luck!
Post Reply