Nothadoth Posted August 14, 2006 Share Posted August 14, 2006 im trying to put product ids on my website for my sales. but different categories will be in different tables in the database. if in each one it is a id that goes 1,2,3 etc. they will clash. So i was thinking maybe an auto-increment that would go 1,2,3 etc. but have letters at the beggining or end to show what category it is in: eg. P1, P2 and F1, F2. Is this possible? or does anyone know an affective way of doing product ids?Thanks Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/ Share on other sites More sharing options...
trq Posted August 14, 2006 Share Posted August 14, 2006 [quote]but different categories will be in different tables in the database[/quote]There is you problem. Why are different categories going into different tables? If product id's need to be unique, they really aught to be. Maybe you should look into database normalization techniques. Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74815 Share on other sites More sharing options...
Nothadoth Posted August 14, 2006 Author Share Posted August 14, 2006 because if they are in different categories i can use a while loop to display all of the categories on a page. is there a better way? Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74820 Share on other sites More sharing options...
king arthur Posted August 14, 2006 Share Posted August 14, 2006 Have another column for category. Auto-increment is designed for ID columns, you should just let it do its job. Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74822 Share on other sites More sharing options...
Nothadoth Posted August 14, 2006 Author Share Posted August 14, 2006 how would i use a while loop to display links to all categories if it has a column with it in? i thought of it before Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74823 Share on other sites More sharing options...
trq Posted August 14, 2006 Share Posted August 14, 2006 [quote]is there a better way?[/quote]Yes. Database normalization. At its simplest you would have a signle table something like...[code]CREATE TABLE products ( id INT PRIMARY KEY, title VARCHAR(80), cat INT)[/code]This enables you to store all your products in a single table, all with a unique id, and all in there own catigories if required. To get the all products, you would simply query something like....[code]SELECT * FROM products GROUP by cat[/code] Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74826 Share on other sites More sharing options...
king arthur Posted August 14, 2006 Share Posted August 14, 2006 [quote author=Nothadoth link=topic=104275.msg415834#msg415834 date=1155599652]how would i use a while loop to display links to all categories if it has a column with it in? i thought of it before[/quote]Well, how are you defining your categories? Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74828 Share on other sites More sharing options...
Nothadoth Posted August 15, 2006 Author Share Posted August 15, 2006 i would have a field called Categoryand it would say like "PC" or "Printers" in it.I need a page where it will display links to all the different categories so you can click it to show all items under that category. Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74835 Share on other sites More sharing options...
simcoweb Posted August 15, 2006 Share Posted August 15, 2006 Just like anything else, your categories need an ID. It could be like:PCPrintersKeyboardsMonitorsor like:CAT1CAT2CAT3or like:123etc.In most shopping carts there's a separate table for category creation containing those ID's. Then, in your product table, you'd have a field for category and reference the proper category ID in that in order to assign the product to the right category. Your while loop would run through the product database and display the products as per category.[code]CREATE TABLE category ( id VARCHAR(80) PRIMARY KEY, title VARCHAR(80), )[/code]Or something like that. Link to comment https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.