CodeIgniter Forums
Please Help!!! one to many relationships? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Please Help!!! one to many relationships? (/showthread.php?tid=11474)



Please Help!!! one to many relationships? - El Forum - 09-10-2008

[eluser]Unknown[/eluser]
Hi everyone,

I am pretty new to code igniter but have some experience with PHP. This is my first production app using CI and I have stumbled at the 1st hurdle.

I am trying to make a system to distribute tasks to employee's. When a new task is loaded in the system I want the user to be able to click a button/link then send the same task to 5 employee's.

The DB will have 3 tables Tasks_table, Staff_table, and Assigned_Tasks_table.

The Assigned_Tasks table will store the key's from the other 2 tables (kinda like a shopping cart).
I have extracted the task_id from the URI and can write that to the Assigned-tasks table, I have also run a query to extract 5 employees with the least number of current tasks.

How do I take the output from this query and insert the staff_id fields of the 5 results into 5 records of the assigned_tasks table?

I hope someone can help, I am really stuck!!

Any questions please ask!


Please Help!!! one to many relationships? - El Forum - 09-10-2008

[eluser]BlackstoneDigital[/eluser]
Hello,

What you would do is do a select statement to get your employees. Try this:

Code:
$taskID = 1; //whatever your query string returned.
$query = $this->db->query("SELECT employeeID FROM Staff_table WHERE tasks < 5"); // or whatever

foreach ($query->result() as $row)
{
   $this->db->query( "INSERT INTO assigned_tasks (employeeID, taskID) VALUES (" . $row->employeeID . ", " . $taskID . ")" );
}

Have a go with that.


Please Help!!! one to many relationships? - El Forum - 09-10-2008

[eluser]Unknown[/eluser]
Thank you so much!

That worked like a charm!!