Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2004, 06:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating many to many

Hi everybody,
Im rebuilding a course database for a college's website and im in need of some advice.

I have a selection box which im using for selecting multiple subjects.
As there is a many to many relationship i have a table for joining the records. When updating the course I want the previously selected subjects to be selected when the page loads so the user can unselect them to remove that subject from the course. would my best option be to delete the previous records then add them all again?
 
Old March 10th, 2004, 12:21 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That's usually the way you have to do it because there's no simple way to telling from the posted data of an HTML form what was "un-selected". This applies to checkboxe and select controls. The easiest way is to just clean out all records applicable then add in the selected ones.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 11th, 2004, 05:34 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another thing. I first thought getting the already selected options selected when the page loads would be a simple case of checking against the record set, forgetting that it would have to loop through each record in the rs for each option, is there a better way? would it be best to put all the id numbers into a string then doing an instr() for each option, this page is only going to be used by a few people at a time (like 3 or 4 max)

thanks for your help
Andy
 
Old March 11th, 2004, 10:20 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think in the end you are best off to just delete all appropriate rows and then insert the currently selected ones.

Think about it this way... what makes more sense:

A) select current rows from DB, loop thru results, test against current selected items, figure out which to remove, remove them, add new ones.

B) Remove all applicable rows, add all selected items.

Why do all that extra work in option A)? It's going to be less efficient and more hastle.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 11th, 2004, 12:58 PM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats for all the advice :)
i thought this was going to take a while to figure out as im only a novice. Its only taken me a couple of hours to get the whole thing done.
Nice one mate!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a datagrid jgrant ASP.NET 2.0 Basics 0 August 25th, 2007 07:34 PM
Updating Labels in C# dranne C# 3 April 10th, 2007 12:37 AM
Updating Recordset arholly Access VBA 16 December 27th, 2006 01:28 PM
database not updating ellie BOOK: Beginning ASP 3.0 1 April 16th, 2006 05:28 AM
Updating dmurray Access 1 June 25th, 2003 05:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.