Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Expanding on database fields

Posted on 2004-09-16
6
Medium Priority
?
167 Views
Last Modified: 2008-03-06
Hi,

I have a database that contains,

Client ID
Username
Password
Domains etc...

But also want the Domains field to hold, Domain Name, Username, Password, Date etc, is it possible to do this and how ? or do I have to create another table and reference this ?

Cheers
0
Comment
Question by:MirageSF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
merwetta1 earned 300 total points
ID: 12081598
I think what you're asking is how to store a wide variety of domain info in one field. if that's not true, please clarify.

I suggest using serialize and unserialize to store a variety of info. You put the info into an array, serialize it, and then store it in the database. When you pull it out of the database, you unserialize it and you have your array back.

for example:

$domain_info['domain_name'] = 'whatever.com';
$domain_info['registrar'] = 'network solutions';
$domain_info['username'] = 'user';
$domain_info['password'] = 'pass';
$domain_info['expiration'] = '9/25/04';
## add whatever else you want

$domain_info_serialized = addslashes(serialize($domain_info));
## routine to store $domain_info_serialized in domain field goes here

Then when you want the info back, after you retrieve it from the database, just use something like:

$domain_info = stripslashes(unserialize($data_from_db));
echo "domain: ".$domain_info['domain_name']."<br>";
echo "registrar: ".$domain_info['registrar']."<br>";
echo "username: ".$domain_info['username']."<br>";
echo "password: ".$domain_info['password']."<br>";
## etc.

hope that helps
0
 

Author Comment

by:MirageSF
ID: 12081619
Hi Thankyou thats pretty much correct, but that would allow me to add alot of data to the domain field for example, but what if I want to add another domain to that user, again seralise it and reference it how ?

So some users may have 1 domain in there data, whereas others may have 2 or more, each needs to be stored and referenced.

Cheers
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 200 total points
ID: 12082297
I think it would be better to have a second table and cross reference them.

for example your first table would resemble:

Client ID
Username
Password

etc

Then the second table may look like this:

Client ID
Domain Name
Date

etc

Then your queries can just reference the Client ID to retreive matching information from both tables, hypothetical example:

SELECT * FROM first_table WHERE username='$username' AND password='$password'

you can then use the ID returned from that query to get a list of the domains owned by that user in the second table

SELECT * FROM second_table WHERE Client ID='$clientid'

This means you can have multiple domains owned by one user in induvidual rows in the second table without causing any inconvienience.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:merwetta1
ID: 12087089
the question asked if it was possible, so i gave a solution. but, cross referencing a domain table is by far the best solution. use the serialize trick if you need to store diverse information, and use another table if you need to store repetitive info.
0
 

Author Comment

by:MirageSF
ID: 12133884
Hi,

I decided to split the points 75 - 50, as merwetta1 answer was correct to my question, however Diablo84 I decided to go your root as its more of a practical and easier managed solutions.

Thanks to both of you.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12133914
no problem :)

|)iablo
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question