Solved

Expanding on database fields

Posted on 2004-09-16
6
165 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 75 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 50 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

710 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