This is a simple batch of code, I have tried things such as $Projects = (Object) $array
and others that involve converting arrays to objects, and objects to arrays. My issue always stays the same where when the $_GET
is populated all records from the PE
table are sent into the ProjectEmployees
variable. From there, I use a foreach
to go through each one and take each of the Project IDs
and take the corresponding project and add it to the Projects object
. This object is then sent to a form where all the data is read out and displayed.
My issue is that within the foreach loop the $Projects
object gets overwritten and only ever outputs 1 record, even though I know there should be 2, it is also the second record so I know it is overwriting not just skipping. I know it is reaching that point as the find function is a select * where the EmployeeID = ID
which I have tested within the database itself so I know it should work.
public function list() {
if (isset($_GET['employee'])){
$ProjectEmployees = $this->ProjectEmployeesTable->find('EmployeeID', $_GET['employee']);
foreach($ProjectEmployees as $ProjectEmploy){
$Projects = $this->projectsTable->find('ProjectID', $ProjectEmploy->ProjectID);
}
}
So my question is whether there is any way to correctly iterate the records I want from the ProjectsTable
,according to the project IDs
within the ProjectEmployees
variable, into Projects
.