Storing and Retrieving Multiple Objects From 1 ...

This is a discussion on "Storing and Retrieving Multiple Objects From 1 ..." within the Classic ASP section. This forum, and the thread "Storing and Retrieving Multiple Objects From 1 ... are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Sep 11th, 2004, 05:03
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Storing and Retrieving Multiple Objects From 1 ...

Storing and Retrieving Multiple Objects From 1 Feild. I need to know how this can be done. What I am talking about is instead of making 1000 different empty fields in my database, just make one and make it where when a user selects an item it adds to that field.

FE- 1,2,4 Where 1 is its own item 2 is its own item and 4 is its own item. How would I go about doing this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Sep 11th, 2004, 07:23
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,188
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Can you explain exactly what you are trying to do?

What is the database for. What do the fields represent?

I think there will be a much better way that using 1000 fields (OMG)
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Sep 11th, 2004, 07:34
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
I'm trying to keep track of my user's using a database instead of SessionVariables.. I want to be able to see what items they have chosen to buy or what not As well as how many of each product they are going to buy. I was told to set up my database where I put my products in a seperate table from my user's so that when A user wants to buy something I just Use the ID Number off of that product and put it in a Field Called Buy. But This only works if the user wants to buy a single item. So I was wondering using that logic could I just putt multiple records into that field seperating them with a comma. And how would this be possible?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Sep 11th, 2004, 09:04
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,188
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
yes, you can do this.

The field however would have to be one of the text(string) type fields.

Then, you can just throw multiple values in there seperated by commas.

When pulling them out again in ASP, use the Split(MyString,",") function to return
an array of product numbers.

Again, I dont really think this is the right approach.

I think you would be better storing orders, in two tables. The tables (name in bold) would go something like this:-

tblTransaction
TransID
tr_CustId
tr_Date
tr_Price

tblTransItems
TransItemID
ti_TransID
ti_ProductID
ti_Quantity

Obviously your tables will likely contain more fields, but this approach will make it far easier for you in the long run, and would be the 'normalised' approach to constructing your database.

Reporting will be easier too.

Hope you see the logic here.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Sep 11th, 2004, 17:45
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Why the two tables? I don't understand why I'd use two tables for this. If you say it's the best approach Then I am most certainly sure that it must be cause you know what your talking about.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Sep 11th, 2004, 22:42
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
The answer lies in the relationships between the three tables - tblCustomers, tblTransaction
, tblTransItems. For simplicity, let's rename those to:

tblCustomers
tblBasket
tblBasketItems

tblCustomers lists all the customers (and possibly all their details) and each customer has their own (unique) customerID. The CustomerID field is usually set to auto-number - that is, every new customer that is added to the table is automatically given the next available ID number by the DB. This field is also set as a 'Primary Key'. Let's use this as a simple exmaple table:

CustomerID | CustFirstName

1 | Anna
2 | Dave
3 | Clive
4 | Bob

Here, Anna has a CustomerID of 1. If I add another customer to the table, Ian, he will be automatically assigned a CustomerID of 5 (the next available/unused ID number.)

Every Customer will have at least one shopping basket (but some might want more than one), so we'll create a new table of shopping baskets tblBasket. Again, Each one will have it's own auto-generated ID (called BasketID) as and when a customer starts the shopping process. So we know who's basket is whose, we add the associated Customer ID to tblBasket. Let's say Dave is the first person to start shopping:

BasketID | CustomerID
1 | 2

The Basket Table now shows that it has one basket and it can use the CustomerID (as what's called a Foreign Key) to compare with the Primary Key in tblCustomers and find that this is Dave's basket (CustomerID 2).
With the Primary/Foreign Key relationship set up this way, Dave could theoretically have as many baskets as he wants, as in each case, we just create a new basket, it gets a new Basket ID in tblBaskets, and is set as customerID 2 again:

BasketID | CustomerID
1 | 2
2 | 2

This is know as a one-to-many relationship, since one customer could have many baskets. Although you may not want this Feature right away, it is best practice to build this flexibility into the DB system early, so that it's much easier to facilitate the feature in the future.

Similarly now, Customers will almost certainly want the ability to add more than one product into a basket, so we create a new table, tblBasketItems, with the same relationship structure, but this time, between the Basket and the items in it:

BasketItemID | BasketID | ProductName
1 | 1 | Apple
2 | 1 | Orange
3 | 1 | Banana

tblBasketItems has a Primary Key of BasketItemID, a Foreign Key of BasketID (relating directly to tblBaskets) and a description of the item. Note that we don't need to add the CustomerID to tblBasketItems because we can find that out based on the relationships we have already built:

we can refer to the fields in these tables with the following notation:

[tablename].[fieldname]

So...

tblBasketItems.BasketItemID 3 is a 'Banana'
tblBasketItems.BasketID is 1 (where tblBasketItems.BasketItemID is 3)
tblBaskets.CustomerID 1 is (where tblBaskets.BasketID is 1)
tblCustomers.CustName = 'Dave' (where tblBaskets.CustomerID 1)

In this way we have stored the minimum information (with no duplicate content stored), but created the most flexibility this simple system might ever need.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Sep 12th, 2004, 03:21
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Wow. That's Awesome. Thanks for the Explination. I actually get it now. I'm going to start working on this!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
Old Sep 12th, 2004, 13:00
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
No probs. Maybe I should post this as an article.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #9  
Old Sep 12th, 2004, 15:50
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
that would be good... an <u>in detail</u> article about shopping carts etc in ASP would be very helpful...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #10  
Old Sep 12th, 2004, 16:37
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,188
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
D3mon... I couldnt have put it better myself.

I would love an article on this... not nessesarily ASP focused (you can if you like)... it could be SQL generic for the SQL article section.

Nice reply.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
storing, retrieving, multiple, objects

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching HTML And Storing josephman1988 Other Programming Languages 0 Feb 18th, 2008 13:25
OOP, the new operator & object literal notation - multiple child objects of a parent iporter JavaScript Forum 1 Oct 21st, 2007 07:51
storing lists of friends keyboardcowboy Website Planning 0 May 22nd, 2007 19:14
Storing images as long blobs The Hick Man PHP Forum 4 Jul 3rd, 2006 19:19
Setting/Retrieving Cookies Mike Henson Web Page Design 2 Jan 10th, 2006 20:34


All times are GMT. The time now is 15:55.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42