dwex Posted January 22, 2011 Share Posted January 22, 2011 My table looks like this.. `guns_id` int(255) NOT NULL auto_increment, `guns_name` varchar(255) collate latin1_general_ci NOT NULL, `guns_price` int(255) NOT NULL, PRIMARY KEY (`guns_id`) I want to add a product key that is unique through out the whole database as I have other products other than guns aswell. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted January 22, 2011 Share Posted January 22, 2011 I'm guessing you have other items in the Database such as car_id, car_name, car_price and other stuff. How about giving them all an item_id? indestead of giving each catergory unique ID's? If this is not the case, would you care to explain how your Database is structured? Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 it's just a bunch of that but different products like vest , helmet etc. I want each and every item to be have a different ID even if they are in different tables in the database. Quote Link to comment Share on other sites More sharing options...
merylvingien Posted January 22, 2011 Share Posted January 22, 2011 $today = date('y-m-d'); $secondpart= rand (1, 9999999999); $uniqueidcode= "$today $secondpart"; $uniqueidcode= md5($uniqueidcode); $uniqueidcode is your product id code Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2011 Share Posted January 22, 2011 You don't use different tables just because you have a different produce type. It creates a data management nightmare, like you are having with setting up unique product id's. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted January 22, 2011 Share Posted January 22, 2011 Would you be able to show me how the database tables look currently? Are you wanting to have the ID be a number or letters, or both? Would is be possible to merge the items tables into 1 big table? If not you could just add a new field to all of the items tables and call it item_id a said before and then just add a unique number and/or letter combo manually... Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 something like that. -- -- Table structure for table `headbands` -- CREATE TABLE `headbands` ( `headbands_id` int(250) NOT NULL auto_increment, `headbands_name` varchar(250) collate latin1_general_ci NOT NULL, `headbands_price` varchar(250) collate latin1_general_ci NOT NULL, `headbands_description` varchar(1000) collate latin1_general_ci NOT NULL, `headbands_image` varchar(250) collate latin1_general_ci NOT NULL, `headbands_stock` int(255) NOT NULL, `headbands_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`headbands_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=15 ; -- -- Dumping data for table `headbands` -- -- -------------------------------------------------------- -- -- Table structure for table `helmet` -- CREATE TABLE `helmet` ( `helmet_id` int(255) NOT NULL auto_increment, `helmet_name` varchar(255) collate latin1_general_ci NOT NULL, `helmet_price` int(255) NOT NULL, `helmet_description` varchar(1000) collate latin1_general_ci NOT NULL, `helmet_image` varchar(255) collate latin1_general_ci NOT NULL, `helmet_stock` int(255) NOT NULL, `helmet_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`helmet_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ; -- -- Dumping data for table `helmet` -- -- -------------------------------------------------------- -- -- Table structure for table `shirts` -- CREATE TABLE `shirts` ( `shirts_id` int(250) NOT NULL auto_increment, `shirts_name` varchar(100) collate latin1_general_ci NOT NULL, `shirts_price` varchar(150) collate latin1_general_ci NOT NULL, `shirts_description` varchar(1000) collate latin1_general_ci NOT NULL, `shirts_image` varchar(250) collate latin1_general_ci NOT NULL, `shirts_stock` int(255) NOT NULL, `shirts_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`shirts_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=20 ; Quote Link to comment Share on other sites More sharing options...
ignace Posted January 22, 2011 Share Posted January 22, 2011 CREATE TABLE categories ( category_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, category_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (category_id) ) ENGINE=INNODB; CREATE TABLE items ( item_id INT UNSIGNED NOT NULL AUTO_INCREMENT, category_id SMALLINT UNSIGNED NOT NULL, item_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, item_price DECIMAL(5,2) UNSIGNED NOT NULL, item_description VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, item_image BLOB NOT NULL, item_stock SMALLINT UNSIGNED NOT NULL, item_time DATETIME NOT NULL, PRIMARY KEY (item_id), FOREIGN KEY (category_id) REFERENCES categories (category_id) ) ENGINE=INNODB; If there is any information specific to some item create a new table and let it hold a reference to the items table. Quote Link to comment Share on other sites More sharing options...
dwex Posted January 22, 2011 Author Share Posted January 22, 2011 wow.. that looks so much neater. Think I know what you guys meant now. Thanks alot for your time guys ! Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 22, 2011 Share Posted January 22, 2011 As well as all the other video's in the series. 20 minutes will help you understand how to properly design a database. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.