I am writing a system in ASP
VB to manage news stories on a Website. The stories may appear in an unlimited number of multiple categories (for instance, it could be a feature story, a business story, a regional story, an advertiser’s story, etc.). So I’ve got three tables in the MS SQL 2000 database:
Story (contains the story info, headline, byline, etc.)
Category (contains the Category name)
StoryCat (a junction table with only three columns: StoryCatID, StoryID, and CategoryID)
StoryCat, as you can see, creates the many-to-many relationship between the Story and Category tables.
I have created a form for entering new stories. It saves the story data and then takes you to a second page where you select the categories it can use. This second page has the StoryID and a repeating region with the available category names next to a check box. I’d like the user to be able to select the check box and then, when they submit the form, it will post an INSERT create a new record for each of the check boxes they selected.
So, if you decided to check three boxes, it should create three records in the StoryCat table:
Code:
StoryCatID StoryID CategoryID
1 91 3
2 91 5
3 91 12
I’m really not sure how to approach this problem because the form elements (check boxes) are dynamic, so I guess I need to loop through them and then execute an INSERT command for each one that’s there? I really have no idea how to start this.
Any help or advice will be GREATLY appreciated!