Jump to content

Flexibility of the table header


Go to solution Solved by QuickOldCar,

Recommended Posts

Hi Everyone,

 

After several round of review, I has been rejected. The output that preferred is:

post-179514-0-85228000-1446622643_thumb.jpg

 

I'm not sure it's possible to do it and how to do it. As you can see, the header of program supported,Position,Evaluator will be increase base on the employee records. It's very flexible header, it's depends on number of form that employee supported.

 

  • Employee can submit more than one form (differently).
  • Each form contain of more than 1 question. 
  • The grand total is a sum of all of the form for individual employee.
  • Each form have an evaluator/ position

Actually, i have a different type of output previously. 

The output is more details :

 

post-179514-0-89041000-1446625171_thumb.jpg

$sql = "SELECT EmpID,EmpName,FormName,questions,Scoring,Position,addedBy FROM [Advisory_BoardDB].[dbo].[masterView] WHERE submissionStatus <> 'Draft' ORDER BY EmpName ASC,FormName ASC";    


$stmt = sqlsrv_query($conn, $sql);
$data = array();

while (list($eid, $ename, $fname, $q,$score,$pos,$ab) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
    if (!isset($data[$eid])) {
        // initialize array for employee
        $data[$eid] = array('emp' => $ename, 'total' => 0, 'items' => array());
    }
    // accumulate item data
    $data[$eid]['items'][] = array('form' => $fname,'questions'=> $q,'score' => $score,'position'=>$pos,'addby'=>$ab);
    $data[$eid]['total'] += $score;
}
$pcent20 = ceil(count($data)*20/100);
//$pcent20 = ceil(count($data)*$finalPercentage);
//uasort($data, function($a,$b){return $b['total']-$a['total'];});

uasort($data, function($a, $b)
{
    $emp = $b['total'] - $a['total'];
    if($emp === 0)
    {
        return strcmp($a['emp'], $b['emp']);
    }
    return $emp;
});


$data = array_slice($data, 0, $pcent20, true);


//echo '<pre>',print_r($data, true),'</pre>';

//
//  Now output the array
//
echo <<<TABLE
    <table border="1" id="example">
        <thead>
        <tr>
            <th>Employee ID</th>
            <th>Employee Name</th>
            <th>Grand Total</th>
            <th>Form</th>
            <th>Score</th>
            <th>Position</th>
            <th>Evaluator</th>
        </tr>
       <thead>
TABLE;
echo "<tbody>";
foreach ($data as $eid => $edata) {
    // how many items
    $numItems = count($edata['items']);
    echo "<tr>
            <td rowspan='$numItems'>$eid</td>
            <td rowspan='$numItems'>{$edata['emp']}</td>
            <td rowspan='$numItems'>{$edata['total']}</td>";
    foreach ($edata['items'] as $k => $idata) {
        if ($k > 0) {
            echo "<tr class='hover-row'>";
        }
       echo "<td>{$idata['form']} - {$idata['questions']}</td><td>{$idata['score']}</td><td>{$idata['position']}</td><td>{$idata['addby']}</td></tr>";
    }
}
echo"</tbody>";
echo "</table>";
?>

For More details:

 

http://forums.phpfreaks.com/topic/298608-sql-group-view-to-get-grand-total-and-details/

 

 

Million Thanks.

Link to comment
https://forums.phpfreaks.com/topic/299100-flexibility-of-the-table-header/
Share on other sites

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.