简体   繁体   中英

How to structure a simple database

I would like to construct a database of the following nature:

There are different types of people, and each person does many jobs, example:

cleaner: clean toilet, clean kitchen
maid: do laundry, cook breakfast, cook lunch
gardener: plant flowers, water flowers

I will also have a MySQL database with all of the cleaners, maids, gardeners, etc. The user will write which job he needs into an HTML form and then the PHP file will determine who does the desired job and then select the most appropriate person for the job.

How do I structure the above database? Do I do it just as I did above?

How does PHP "put them together"? Must I use arrays?

Should I put this database directly into the PHP code or in a separate text file (or other kind of file)?

Thanks everyone!

As indicated in the other post, you need to learn basics before you dive into something complicated. There are ample tutorials on web which are easy to understands and get started with.

You may start with this tutorial to get a grasp of working with MySQL and PHP, and then you can use the following schema for your web-application.

people
  people_id (PK)
  name

roles
  role_id (PK)
  role_name

tasks
  task_id (PK)
  role_id (FK)
  task_desc

people_roles
  pr_id (PK)
  people_id (FK)
  role_id (FK)
  • people -- all the employees/people and their details

  • roles -- all the available roles

  • tasks -- tasks that each role is assigned, role and task has one to many relationship (see the FK?)

  • people_roles -- this is a link table that makes may-to-many relation ship between people and roles , so that a gardener can be act as a cook . If you wish to assign so.

Hope this helps.

You need to learn to walk before you can run.

I would do some basic PHP/MySQL tutorials first to get yourself familiar with the very basics of data manipulation. Then maybe to speed up production use a framework, CakePHP would by my recommendation based on it's powerful auto-magic CRUD (Create, Read, Update, Delete - something else to read up on :) ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM