...

View Full Version : Join two tables



levani
05-26-2010, 01:37 PM
I have two tables that holds information about categories on my site. First table consists of two columns: ID and name, second table consists of three columns: id, category id and parent id. The second table describes the connections between categories in order to add sub categories in parent category.
When I add new category one new record is added in both tables. If the category is main - 0 is recorded in the third column of the second table. If it isn't main category, the parent category id is recorded instead.

So I want to retrieve all the main category ids (where parent id is 0) and than retrieve names from first table with these ids... Hope I'm clear...

I'm afraid I'm not so familiar with mysql to handle with this problem myself. Can anyone please help?

abduraooft
05-26-2010, 03:13 PM
I have two tables that holds information about categories on my site. First table consists of two columns: ID and name, second table consists of three columns: id, category id and parent id. The second table describes the connections between categories in order to add sub categories in parent category. Why do you need a second table for this? Can't you just add a parent_id column in the first table itself to indicate the relation? Take a look at a sample design at http://www.codeassembly.com/How-to-display-inifinit-depth-expandable-categories-using-php-and-javascript



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum