Re: PHP/MySql - address book
| From: | Andrey Hristov | Date: | Sun, 06 Jan 2002 17:38:35 +0000 |
| Subject: | Re: PHP/MySql - address book | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-79613@lists.php.net to get a copy of this message | ||
The answer to your question is the relational model of databases.
So instead of one big table, you have to use 2. Say first table is employee and the second -
companies.
in the employee we have some fields and one of them is company_id,
this id corresponds to a single row in the companies table. companies table contains several fields
nut one of them is company_id.
company_id is a foreign key (the link you ask).
How to get all employees from single company:
select employee.* from employee,companies where employee.company_id=companies.company_id and
companies.company_name='Some Ltd.
Inc.';
or better
select employee.* from employee left join companies using(company_id) where company_name='Some
Ltd Inc.';
I do not have links to literature about relational model but I remember that on www.phpbuilder.com
there is/are some info on it.I
think from y.2000.
Regards,
Andrey Hristov
Andrey Hristov
Web Developer
----- Original Message -----
From: "sg" <sguillon@freesurf.fr>
To: <php-db@lists.php.net>
Sent: Sunday, January 06, 2002 7:26 PM
Subject: [PHP-DB] PHP/MySql - address book
> Hi,
>
> I'm trying to do a sort of address book where I'd put all information about
> anybody or any company from which I receive informtation (friend, people
> from work, hotels, places...)
>
> An entry starts with a name, then I can have any type of information. The
> table I'm using has a lot of fields, but I display via PHP only those that
> are not empty.
>
> I'm now facing a problem many must have already faced. A lot of people work
> for the same company, and I'd like to have a separate table or storage area
> to put that data, so that I don't have to write the same company addresse
> twice, and if that information changes, I won't have to go through ten or
> twenty people's entries to modify it.
>
> So how would I link a company's information to a person's entry?
>
> I know it may sound easy or ridiculous a question, but though I know HTML
> very well I'm still a beginner (learning on my own) et PHP and MySql.
>
> So far I have a neat rendering of the database I've created, but I feel I
> should look further into DB use.
>
> Software I'm using:
>
> EasyPHP (latest version)
> PHP 4
> MySql
> PhpMyAdmin
>
> on Windows Me
>
> Main question, I repeat is : how would I link a company's information to a
> person's entry?
>
> Cheers
>
> SИbastien
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>