Storing dynamic URL's

Associate
Joined
30 Nov 2003
Posts
1,591
Let's see if I can explain this ok.. Basically I have a site (not written by me so getting my head around the confusing code) and the product category pages use dynamically created URL's.

I want to use these URL's to put on my products pages so I can list all the categories each product is in. But, as these URL's are not stored anywhere I'm not sure how to go about calling them. Is the best way going to be to modify the site to store the page URL's in MySQL? Or could they be stored within variables in PHP? A little guidance would be great! Thanks in advance, this is a PHP/MySQL site by the way.
 
You'll need to generate the URL yourself on the product page. Does the products table have a "category" column and is there a sensible mapping between a category and its URL (e.g. www.site.com/products/cpu)? If so then when you query the products table to render a particular product page you'll just use the "category" value to generate the URL.

Edit

I appreciate you did actually ask about storing URLs but I didn't mention anything of the sort. Well I would consider this bad practice. If you move your site to a different domain then these links become invalid. Ideally you'd have some globally accessible variable called something like $rootDir that stores the web root then within code you'd concatenate the path to a resource (e.g. $rootDir.'/products/'.$category)
 
Last edited:
Back
Top Bottom