Jump to content

User assigned in mysql table


blmg2009

Recommended Posts

Hi there, 

 

I'm fairly new to PHP and I'm self teaching. 

 

I'm sure this will be out there somewhere but I can't for the life of me think of the terminology to search the net and find the solution. 

 

I'm creating a Task Manager; 

 

Each task can be assigned to many users at once. 

 

I'm creating a text field in the task field, this text field will include user ids separated by commas.

 

I believe I can explode this data to handle each id.

 

However how can I build a php script that will show the user all the task assigned too them.

 

If it did a search LIKE in the text field. The id could be confused with others.

 

If someone knows the solutions I would be very greatful.

 

thanks for reading   

Link to comment
Share on other sites

Your problem could be in the db design, not in your programming.  It is generally not recommended to have db fields/columns containing multiple pieces of like data.  In your case you are talking about storing multiple tasks, comma-separated, within one table column.  The correct design (normalized) would be to have  users in one table then tasks assigned to those users in a second table, in a one-to-many relationship.  The task table would have the task id and the user id as two fields which you then can query directly  and join to both the users table for user data if necessary, as well as a new taskname table for descriptions of the tasks.

 

table users - userid, username, other user data

table taskname - taskid, taskname, other task data

table tasks - tasked, userid, date assigned?, date completed?, etc.

Link to comment
Share on other sites

Thank you for replying; 

 

Maybe should explain the database design in more detail:

 

Users

id

username
first_name
last_name 

 

 

Task

id

title
description
deadline
date_created
assigned_users

Objectives
id
task_id
title
description
assigned_users
deadline
date_created

Objectives are sub tasks of the main task. For example, Task "Build Task Manager", Objective "Create database design", Objective "Build html page"

 

If I was to create another table as you have suggested with assigned tasks to users then after a while that table would fill up with a lot of data

Where as I was thinking to maybe use {1},{2},{14} in a text field called assigned_users in order to reduce the amount of data in the database. 

 

I presumed this would be good practice, or I'm wrong? :confused:  

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.