Davie33 Posted June 14, 2012 Share Posted June 14, 2012 Hi can anyone tell me the best way to set up an sql for categories.Am making a site for selling computers but wanted to know how i go about doing this for sql as i would like say, i had categories like this.... CREATE TABLE IF NOT EXISTS `cats` ( `id` int(11) NOT NULL AUTO_INCREMENT, `catname` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM CHARACTER SET = utf8 COLLATE utf8_unicode_ci AUTO_INCREMENT=11 ; INSERT INTO `cats` (`id`, `catname`) VALUES (1, 'Intel'), (2, 'Amd'), (3, 'Ati Radeon'), (4, 'nNvidia'), (5, 'Motherboards'), (6, 'Cpu'), (7, 'Harddrive'), (8, 'Cases'), (9, 'Peripherals'), (10, 'Software'), (11, 'Computer Systems'), so say i had "Computer Systems" in right column as a link to that categorie page and when u go to that page if will show a few more from the categories sql say intel and amd. am i going in the right direction with this ?. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 Assuming you only want (a) a single category per item, and (b) no subcategories, then yes. Quote Link to comment Share on other sites More sharing options...
Davie33 Posted June 22, 2012 Author Share Posted June 22, 2012 Thanks wasn't to sure but made code and all works for the catnames to show as links thanks. Now i c you have said something about subcats how would i enter that in database ?. Quote Link to comment Share on other sites More sharing options...
Barand Posted June 22, 2012 Share Posted June 22, 2012 Easiest way is to add a parent column to your category table. Add subcats to the table with parent = id of the parent category. Top level categories have a parent value of 0. Quote Link to comment Share on other sites More sharing options...
Davie33 Posted June 24, 2012 Author Share Posted June 24, 2012 Ok thanks Barand . 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.