I have the following tables
tbl_cat -- id(pk), category (PRODUCT CATEGORIES)
tbl_subcat - id, catid, subcat (catid is a foregin key referencing id in tbl_cat ) - SUB CATEGORIES
I want to prepopulate my tables with categories and sub-categories of products. it's quite straightforward to insert categories in tbl_cat but each entry in tbl_subcat must reference a category. For example if i have a category called Acessories, then all items in the subcategory like wristbands, necklace and rings should all have thesame catid that references Acessories in the tbl_cat table.
How can i implement this. Thanks
dhani09
3
Newbie Poster
Recommended Answers
Jump to PostDo you want to know how to add the actual foreign key constraint? or how to manage the data insertion?
Jump to PostYou will need to populate the tbl_cat first. (I am going to assume your
id
fields for both tables areauto_increment
)INSERT INTO tbl_cat (category) VALUES ('Accessories');
The easiest way to do the child table insertions is to manually check the
id
generated …
All 5 Replies
|-|x
126
Junior Poster in Training
dhani09
3
Newbie Poster
|-|x
126
Junior Poster in Training
dhani09
3
Newbie Poster
dhani09
3
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.