blmg2009 Posted December 17, 2014 Share Posted December 17, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/293152-user-assigned-in-mysql-table/ Share on other sites More sharing options...
ginerjm Posted December 17, 2014 Share Posted December 17, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293152-user-assigned-in-mysql-table/#findComment-1499881 Share on other sites More sharing options...
blmg2009 Posted December 17, 2014 Author Share Posted December 17, 2014 Thank you for replying; Maybe should explain the database design in more detail: Users id usernamefirst_namelast_name Task id titledescriptiondeadlinedate_createdassigned_usersObjectivesidtask_idtitledescriptionassigned_usersdeadlinedate_createdObjectives 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 dataWhere 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? Quote Link to comment https://forums.phpfreaks.com/topic/293152-user-assigned-in-mysql-table/#findComment-1499883 Share on other sites More sharing options...
ginerjm Posted December 17, 2014 Share Posted December 17, 2014 But that is exactly what you need to do. Do not worry about the size of your tables. That's what RDMS are designed for. Besides all you will have in the assigned-tasks table will be the tasked and the userid. 1 Quote Link to comment https://forums.phpfreaks.com/topic/293152-user-assigned-in-mysql-table/#findComment-1499885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.