Jump to content

Recommended Posts

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.

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.