Plugnz13 Posted February 12, 2020 Share Posted February 12, 2020 Hi There, I'm trying to get the following array to work as a separate include php file to make the HTML easier to follow. Within the HTML it has been working fine, as the "echo $tdata_consent Variable is within the main curly brackets. As soon as I move the variable outside of the brackets I only get 1 item from the array rather than all of the items. $projects_const = array(); $required_const = ['Consent']; $colors_const = array_combine($required_const, ['bg-danger text-white font-weight-bold'] ); $xml_const=simplexml_load_string($jobs_task_response) or die("Error: Cannot create object"); foreach($xml_const->Jobs->Job as $item_const) { if (in_array((string)$item_const->State, $required_const)) { $projects_const[] = array( 'job_no' => (string)$item_const->ID, 'job_name' => (string)$item_const->Name, 'job_start' => date('d/m/Y', strtotime($item_const->StartDate)), 'job_due' => date('d/m/Y', strtotime($item_const->DueDate)), 'job_status' => (string)$item_const->State, 'job_staff' => (string)$item_const->Assigned->Staff->Name, ); } } usort($projects_const, function($a,$b) {return $b['job_due'] <=> $a['job_due']; } ); foreach ($projects_const as $proj_const) { $job_no =$proj_const['job_no']; $job_name =$proj_const['job_name']; $job_status =$proj_const['job_status']; $job_staff =$proj_const['job_staff']; $job_due =$proj_const['job_due']; $clr_1 = $colors_const[$job_status]; $tdata_const = ''; $tdata_const .= "<div class='row no-gutters'>"; $tdata_const .= "<div class='col-sm bg-white border rounded'><a href='managejob.php?job_id=$job_no' class='text-left ml-1'><strong>$job_no</strong></a></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_name</p></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'>" . state_dropdown_1($job_no, $job_status, $clr_1) . "</div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_status</p></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_staff</p></div>"; } echo $tdata_const; Any thoughts would be much appreciated. Thanks in Advance. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 12, 2020 Share Posted February 12, 2020 1 hour ago, Plugnz13 said: $tdata_const = ''; That line clears the data each time through the loop. Put it before the foreach() loop. Quote Link to comment Share on other sites More sharing options...
Plugnz13 Posted February 12, 2020 Author Share Posted February 12, 2020 Thank you Barand! That makes so much sense! Really appreciate your help. Quote Link to comment 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.