472,345 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

store info in database.

Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other
id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???

Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)

Christopher Brandsdal

Jul 19 '05 #1
4 2583
If you have two tables in your database, one called Companies and one called
People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being
the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple
companies then you need to create a many-to-many relationship-- meaning one
company has many people working for it, but also one person has worked (or
is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a
duplicate entry would be acceptable. For example: if you are tracking an
employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys as
Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a
problematic solution. Besides being difficult to maintain and parse....how
would you decide how much data the field could hold?


"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???
Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)
Christopher Brandsdal

Jul 19 '05 #2
Ok. Thanks I understand.

But the the problem is that both companies and persons are in the same
table...

Should I change it to 2 different tables???

and how will the code look like with the join command???

When I add a person to the database I have to be able to select multiple
companies for that person...
(the companies are added in advance)

"TomB" <sh*****@hotmail.com> skrev i melding
news:O1**************@TK2MSFTNGP12.phx.gbl...
If you have two tables in your database, one called Companies and one called People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being
the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple
companies then you need to create a many-to-many relationship-- meaning one company has many people working for it, but also one person has worked (or
is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a
duplicate entry would be acceptable. For example: if you are tracking an
employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys as Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a problematic solution. Besides being difficult to maintain and parse....how would you decide how much data the field could hold?


"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies in the same database. I wonder how i could connect a person to several

other
id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the ,

???

Hmm..
This may be difficult to ynderstand, but I have tried my best to explain

;)

Christopher Brandsdal


Jul 19 '05 #3
Unless there's a REALLY good reason, then you should separate the data into
two tables. Try to think of the contents of a table as being a list of
similar entities. So Companies would be in a separate table from People,
because they are dissimilar.

If you are using Access create the tables you need, then go the
relationships (icon on toolbar) to indicate how the tables are related.
Once Access "knows" how the tables are related, you can go into the Query
Wizard and create a query (or use design view)
View the query to ensure the results are what you expect.
Switch to SQL view of the query, and you'll see the SQL statement needed to
select the data.

When you are adding people to database, you want to add multiple companies.
I assume therefore, that you'll have three tables (many to many)

Present the form with fields for the Person information, and checkboxes for
the available companies. To make life easier, give each checkbox the same
name, but a different value. For example:

<input type=checkbox name=Companies value="3">McDonalds
<input type=checkbox name=Companies value="4">Burger King

Where 3 and 4 are the UniqueIDs of the two companies.

On the page the form is posted to, "Requesting" the Companies will return a
comma separated list of the selected companies. So if both of the values
were selected in the example above, then Request.Form("Companies") would
return "3, 4"

You will then have to insert the data in three steps.
1) insert the person's information
2)get the new person's ID
3) insert the companies
<%
'Step One
Dim sSQL
Dim RS
Dim PersonID
Dim arrCompanies
Dim iLoop

sSQL="INSERT INTO People (FirstName, LastName) VALUES('Joe',
'Blow')" 'Obviously you would use the values passed in

CN.Execute sSQL 'I'm assuming CN is a properly opened connection
object
'Step Two
Set RS=CN.Execute("SELECT @@IDENTITY") 'returns the most recently
created Identity on this connection
PersonID=RS.Fields(0).Value
Set RS=nothing

'Step Three
arrCompanies=Split(Request.Form("Companies"),",") 'split takes a
string and "splits" it into an array based on the delimiter (in this case a
comma)

For iLoop = 0 to UBound(arrCompanies)
sSQL="INSERT INTO CompaniesPeopleJoin (PersonID, CompanyID)
VALUES(" & PersonID & ", " & Trim(arrCompanies(iLoop)) & ")"
CN.Execute sSQL
Next

%>

Bear in mind, that if any of the inserts fail the previous ones would have
succeeded so you would have only some of the values in.
A better solution would use a transaction, and the best solution would use a
Stored Procedure (Sql Server)

"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
Ok. Thanks I understand.

But the the problem is that both companies and persons are in the same
table...

Should I change it to 2 different tables???

and how will the code look like with the join command???

When I add a person to the database I have to be able to select multiple
companies for that person...
(the companies are added in advance)

"TomB" <sh*****@hotmail.com> skrev i melding
news:O1**************@TK2MSFTNGP12.phx.gbl...
If you have two tables in your database, one called Companies and one called
People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple companies then you need to create a many-to-many relationship-- meaning

one
company has many people working for it, but also one person has worked (or is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a duplicate entry would be acceptable. For example: if you are tracking an employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys

as
Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a
problematic solution. Besides being difficult to maintain and

parse....how
would you decide how much data the field could hold?


"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with

companies in the same database. I wonder how i could connect a person to several

other
id's in a table.

I wonder if I can make a string in the database that holds all the id's separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the

, ???

Hmm..
This may be difficult to ynderstand, but I have tried my best to
explain ;)

Christopher Brandsdal



Jul 19 '05 #4
Hello,

Use the split command, which will then parse out all the commas and put all
the numbers into an array.
Dim tempStr
tempStr = "1,2,3,4,5,6,7,8"

Dim tempArray
tempArray = split(tempStr, ",")

Dim maxArrayElements
maxArrayElements = UBound(tempArray)

Dim arrayIndex
arrayIndex = 0

For arrayIndex = 0 to maxArrayElements - 1
' do what you need to do here, using
' tempArray(arrayIndex)
' to get at the current array value
Next

This example is in vbscript, although Javascript also supports the SPLIT
command....

Joe

"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???
Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)
Christopher Brandsdal

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lars Behrens | last post by:
Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and...
3
by: faktujaa | last post by:
Hi, Currently im storing the connection info. in XML file on the C drive. the only problem with this is that anybody can open and check the...
5
by: Joakim Westman \(Elicit AB\) | last post by:
Hi! I have a page that generates a lot of HTML, and I am considering different solutions to constrain the amount of code that is sent back to the...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the...
5
by: Rob | last post by:
Where is the best place to store database connection info in a vb.net program ? I do not want to "hard-code" a database name into my program....
1
by: rdemyan via AccessMonster.com | last post by:
I'm trying to implement a licensing scheme. There are three types of licenses: Trial - good for 30 to 60 days Interim - good for 1 year Fully...
8
by: Merk | last post by:
I'm looking for a safe and maintainable way to store connection string info (connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app);...
4
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather...
2
by: Alex | last post by:
Hey Guys.. I'm just now starting to learn VB 2005, but I have a question that might help me in the long run. I hope to write applications which...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.