Problem in displaying data inside table format

Hi,

Sorry I forgot to attached the image.

Here the attached image .

Thank you so much

Thank you so much…for your help…I really appreciate it.

Did you see now the screenshot?

Thank you.

Attachments Pending Approval

While we’re waiting for images to be approved, here’s a shot with compound totals.

Hi,

The display is correct also the computation of total.

Is it possible that we can add also a total on the rightside per date

for example

Compound-----------2013-07-22-------
Core Molding–C-R-SC-SP-SS-T-TI–Total
P41------------2.92-3.57-2.33–3.39 12.21 and like the total below of compound the total on the right side should has a color backgournd also…

Thank you so much

Here ya go.

<?php
ob_start();
include "connection.php";
/*
Assuming that $id is called by other means but
defined here for testing.  So instead of checking
IF $id is a particular number, we check that it is set
and query for specific week without adjustment in query
*/
$id = "29";

//$id = $_POST['id'];
if(isset($id)){
    /*
    We are building an array of all information with a single query.
    */
    $Reports = array();
   // $dates = array();
   // $process_names = array();
   // $reject_types = array();
   // $compound_types = array();
   // $rejects = array();
   // $reject_total = array();
    $sql = "SELECT
    r.reject_date,
    r.reject,
    r.process_id,
    r.reject_type,
    r.compound_type,
    p.process_name
    FROM op_reject AS r
    JOIN process_list AS p
    ON (p.process_id = r.process_id)
    WHERE WEEK(reject_date) = '$id'
    ORDER BY r.reject_date, compound_type  ASC";
    $res = mysql_query($sql);
    $k=0;
    while($row = mysql_fetch_assoc($res)){
        $Reports[$k]['reject_date'] = $row['reject_date'];
        $Reports[$k]['process_name'] = $row['process_name'];
        $Reports[$k]['reject_type'] = $row['reject_type'];
        $Reports[$k]['compound_type'] = $row['compound_type'];
        $Reports[$k]['reject'] = $row['reject'];
       $k++;
    }

    //| *************************************************** |\\\\
    //| Build functions to return specific values or arrays |\\\\
    //| *************************************************** |\\\\

    // Returns dates array \\\\
    function dates($array){
        $dates = array();
        foreach($array as $k => $v){
            $dates[] = $v['reject_date'];
        }
        $dates = array_unique($dates);
        sort($dates);
        return $dates;
    }

    // Returns process_names array \\\\
    function process_names($array){
        $process_names = array();
        foreach($array as $k => $v){
            $process_names[] = $v['process_name'];
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        return $process_names;
    }

    //*****************************************//
       // Returns number of columns by date \\\\
    //*****************************************//
    function columns($array,$date){
        //process names
        $process_names = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $date){
                $process_names[] = $v['process_name'];
            }
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        // get reject_types by process name
        $reject_types = array();
        foreach($process_names as $process_name){
            foreach($array as $k => $v){
                if ($v['reject_date'] == $date &&
                    $v['process_name'] == $process_name){
                    $reject_types[$process_name][$v['reject_type']] = $v['reject_type'];
                }
            }
        }
        //Convert reject_type to count
        $counts = array();
        foreach($reject_types as $reject_type){
            $counts[] = count($reject_type);
        }
        //return largest value
        $max_count = max($counts);
        return $max_count;
    }
    //*****************************************//
     // END Returns number of columns by date \\\\
    //*****************************************//

    // Returns compound_type array for process_name \\\\
    function compound_types($array,$process_name){
        $compound_types = array();
        foreach($array as $k => $v){
            if ($v['process_name'] == $process_name){
                $compound_types[] = $v['compound_type'];
            }
        }
        $compound_types = array_unique($compound_types);
        sort($compound_types);
        return $compound_types;
    }

    // Returns reject_type array for date and process_name \\\\
    function reject_types($array,$reject_date,$process_name){
        $reject_types = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name){
                $reject_types[] = $v['reject_type'];
            }
        }
        $reject_types = array_unique($reject_types);
        sort($reject_types);
        return $reject_types;
    }

    // Returns reject amount for cell \\\\
    function searchresults($array,$reject_date,$process_name,$reject_type,$compound_type){
        $result = "";
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == "{$reject_date}" &&
                $v['process_name'] == "{$process_name}" &&
                $v['reject_type'] == "{$reject_type}" &&
                $v['compound_type'] == "{$compound_type}"){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns reject total based on $reject_date,$process_name,$reject_type \\\\
    function resulttotals($array,$reject_date,$process_name,$reject_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['reject_type'] == $reject_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns compound total based on $reject_date,$process_name,$compound_type \\\\
    function compound_resulttotals($array,$reject_date,$process_name,$compound_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['compound_type'] == $compound_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

//echo "<pre>";
//print_r($Reports);
//echo "</pre>";

////Build display data BEFORE output to browser////
$display = "<table border=0 cellpadding=0 cellspacing=0 class=\\"display\\">
        <thead>
            <tr>
                <th>Compound</th>\\r";
                //I'll keep your id identifier in place
                $i=1;
                $dates = dates($Reports);
                foreach($dates as $date){
                    //We'll run our columns function in our date loop to get column count
                    $cols = columns($Reports,$date);

                    $display .= "<th id=col".$i." colspan=\\"$cols\\" class=\\"border\\">$date</th>\\r";
            		$display .= "<th>&nbsp;</th>\\r";

                    $i++;
                }
            $display .= "</tr>
            </thead>";

                $process_names = process_names($Reports);
                foreach($process_names as $process_name){
                    $display .= "<tr>\\r";
                        $display .= "<td>$process_name</td>\\r";

                    foreach($dates as $date){
                           $bor=0;
                        $reject_types = reject_types($Reports,$date,$process_name);
                        $reject_type_count = count($reject_types);
                        $type_for_date = (!empty($reject_types) ? "true" : "false");
                        $cols = columns($Reports,$date);

                        if ($type_for_date == "false"){
                            for($c=0;$c<$cols;$c++){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>&nbsp;</td>\\r";

                                $bor++;
                            }
                        }else{
							$rt_running_count=0;
                            foreach($reject_types as $reject_type){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>$reject_type</td>\\r";

                                $bor++;
								$rt_running_count++;
                            }
							if ($rt_running_count==$reject_type_count){
	                            for($d=$reject_type_count;$d<$cols;$d++){
	                                $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                $display .= "<td$border>&nbsp;</td>\\r";
	
	                                $bor++;
	                            }
							}
                        }
            		$display .= "<td class=\\"border\\">Total</td>\\r";
                    }
            $display .= "</tr>\\r";
                $compound_types = compound_types($Reports,$process_name);
                        foreach($compound_types as $compound_type){
                            $display .= "<tr>\\r";
                                $display .= "<td>$compound_type</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');

                                        $display .= "<td$border>&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
								
									$ct_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');
                                        $reject = searchresults($Reports,$date,$process_name,$reject_type,$compound_type);
                                        $reject = (!empty($reject) ? $reject : "&nbsp;");

                                        $display .= "<td$border>$reject</td>\\r";

                                        $bor++;
										$ct_running_count++;
										
										if ($ct_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                            $display .= "<td$border>&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
									
                                        $compoundTotal = compound_resulttotals($Reports,$date,$process_name,$compound_type);
                                        $compoundTotal = (!empty($compoundTotal) ? $compoundTotal : "&nbsp;");

                                        $display .= "<td class=\\"total border\\">$compoundTotal</td>\\r";
                                }
                            }
            $display .= "</tr>\\r";
                        }

           //---total rejects per process and per reject type---//
                        $display .= "<tr>\\r";
                        $display .= "<td class=\\"total\\">Total</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " border" : '');

                                        $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
									$rt_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " border" : '');
                                        $rejectTotal = resulttotals($Reports,$date,$process_name,$reject_type);
                                        $rejectTotal = (!empty($rejectTotal) ? $rejectTotal : "&nbsp;");

                                        $display .= "<td class=\\"total$border\\">$rejectTotal</td>\\r";

                                        $bor++;
										$rt_running_count++;

										if ($rt_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " border" : '');
	
	                                            $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
                                }
	                            $display .= "<th class=\\"border\\">&nbsp;</th>\\r";
                            }
                        $display .= "</tr>\\r";
                        }
    $display .= "</table>\\r";
}


        if(isset($display)){
            echo "$display";
        }
?>

Thank you… I will try it later and i will update you.

Thank you

I just added align=“right” to those numbers so it looks a little better.

<?php
ob_start();
include "connection.php";
/*
Assuming that $id is called by other means but
defined here for testing.  So instead of checking
IF $id is a particular number, we check that it is set
and query for specific week without adjustment in query
*/
$id = "29";

//$id = $_POST['id'];
if(isset($id)){
    /*
    We are building an array of all information with a single query.
    */
    $Reports = array();
   // $dates = array();
   // $process_names = array();
   // $reject_types = array();
   // $compound_types = array();
   // $rejects = array();
   // $reject_total = array();
    $sql = "SELECT
    r.reject_date,
    r.reject,
    r.process_id,
    r.reject_type,
    r.compound_type,
    p.process_name
    FROM op_reject AS r
    JOIN process_list AS p
    ON (p.process_id = r.process_id)
    WHERE WEEK(reject_date) = '$id'
    ORDER BY r.reject_date, compound_type  ASC";
    $res = mysql_query($sql);
    $k=0;
    while($row = mysql_fetch_assoc($res)){
        $Reports[$k]['reject_date'] = $row['reject_date'];
        $Reports[$k]['process_name'] = $row['process_name'];
        $Reports[$k]['reject_type'] = $row['reject_type'];
        $Reports[$k]['compound_type'] = $row['compound_type'];
        $Reports[$k]['reject'] = $row['reject'];
       $k++;
    }

    //| *************************************************** |\\\\
    //| Build functions to return specific values or arrays |\\\\
    //| *************************************************** |\\\\

    // Returns dates array \\\\
    function dates($array){
        $dates = array();
        foreach($array as $k => $v){
            $dates[] = $v['reject_date'];
        }
        $dates = array_unique($dates);
        sort($dates);
        return $dates;
    }

    // Returns process_names array \\\\
    function process_names($array){
        $process_names = array();
        foreach($array as $k => $v){
            $process_names[] = $v['process_name'];
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        return $process_names;
    }

    //*****************************************//
       // Returns number of columns by date \\\\
    //*****************************************//
    function columns($array,$date){
        //process names
        $process_names = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $date){
                $process_names[] = $v['process_name'];
            }
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        // get reject_types by process name
        $reject_types = array();
        foreach($process_names as $process_name){
            foreach($array as $k => $v){
                if ($v['reject_date'] == $date &&
                    $v['process_name'] == $process_name){
                    $reject_types[$process_name][$v['reject_type']] = $v['reject_type'];
                }
            }
        }
        //Convert reject_type to count
        $counts = array();
        foreach($reject_types as $reject_type){
            $counts[] = count($reject_type);
        }
        //return largest value
        $max_count = max($counts);
        return $max_count;
    }
    //*****************************************//
     // END Returns number of columns by date \\\\
    //*****************************************//

    // Returns compound_type array for process_name \\\\
    function compound_types($array,$process_name){
        $compound_types = array();
        foreach($array as $k => $v){
            if ($v['process_name'] == $process_name){
                $compound_types[] = $v['compound_type'];
            }
        }
        $compound_types = array_unique($compound_types);
        sort($compound_types);
        return $compound_types;
    }

    // Returns reject_type array for date and process_name \\\\
    function reject_types($array,$reject_date,$process_name){
        $reject_types = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name){
                $reject_types[] = $v['reject_type'];
            }
        }
        $reject_types = array_unique($reject_types);
        sort($reject_types);
        return $reject_types;
    }

    // Returns reject amount for cell \\\\
    function searchresults($array,$reject_date,$process_name,$reject_type,$compound_type){
        $result = "";
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == "{$reject_date}" &&
                $v['process_name'] == "{$process_name}" &&
                $v['reject_type'] == "{$reject_type}" &&
                $v['compound_type'] == "{$compound_type}"){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns reject total based on $reject_date,$process_name,$reject_type \\\\
    function resulttotals($array,$reject_date,$process_name,$reject_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['reject_type'] == $reject_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns compound total based on $reject_date,$process_name,$compound_type \\\\
    function compound_resulttotals($array,$reject_date,$process_name,$compound_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['compound_type'] == $compound_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

//echo "<pre>";
//print_r($Reports);
//echo "</pre>";

////Build display data BEFORE output to browser////
$display = "<table border=0 cellpadding=0 cellspacing=0 class=\\"display\\">
        <thead>
            <tr>
                <th>Compound</th>\\r";
                //I'll keep your id identifier in place
                $i=1;
                $dates = dates($Reports);
                foreach($dates as $date){
                    //We'll run our columns function in our date loop to get column count
                    $cols = columns($Reports,$date);

                    $display .= "<th id=col".$i." colspan=\\"$cols\\" class=\\"border\\">$date</th>\\r";
            		$display .= "<th>&nbsp;</th>\\r";

                    $i++;
                }
            $display .= "</tr>
            </thead>";

                $process_names = process_names($Reports);
                foreach($process_names as $process_name){
                    $display .= "<tr>\\r";
                        $display .= "<td>$process_name</td>\\r";

                    foreach($dates as $date){
                           $bor=0;
                        $reject_types = reject_types($Reports,$date,$process_name);
                        $reject_type_count = count($reject_types);
                        $type_for_date = (!empty($reject_types) ? "true" : "false");
                        $cols = columns($Reports,$date);

                        if ($type_for_date == "false"){
                            for($c=0;$c<$cols;$c++){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>&nbsp;</td>\\r";

                                $bor++;
                            }
                        }else{
							$rt_running_count=0;
                            foreach($reject_types as $reject_type){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>$reject_type</td>\\r";

                                $bor++;
								$rt_running_count++;
                            }
							if ($rt_running_count==$reject_type_count){
	                            for($d=$reject_type_count;$d<$cols;$d++){
	                                $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                $display .= "<td$border>&nbsp;</td>\\r";
	
	                                $bor++;
	                            }
							}
                        }
            		$display .= "<td class=\\"border\\">Total</td>\\r";
                    }
            $display .= "</tr>\\r";
                $compound_types = compound_types($Reports,$process_name);
                        foreach($compound_types as $compound_type){
                            $display .= "<tr>\\r";
                                $display .= "<td>$compound_type</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');

                                        $display .= "<td$border>&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
								
									$ct_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');
                                        $reject = searchresults($Reports,$date,$process_name,$reject_type,$compound_type);
                                        $reject = (!empty($reject) ? $reject : "&nbsp;");

                                        $display .= "<td$border align=\\"right\\">$reject</td>\\r";

                                        $bor++;
										$ct_running_count++;
										
										if ($ct_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                            $display .= "<td$border>&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
									
                                        $compoundTotal = compound_resulttotals($Reports,$date,$process_name,$compound_type);
                                        $compoundTotal = (!empty($compoundTotal) ? $compoundTotal : "&nbsp;");

                                        $display .= "<td class=\\"total border\\" align=\\"right\\">$compoundTotal</td>\\r";
                                }
                            }
            $display .= "</tr>\\r";
                        }

           //---total rejects per process and per reject type---//
                        $display .= "<tr>\\r";
                        $display .= "<td class=\\"total\\">Total</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " border" : '');

                                        $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
									$rt_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " border" : '');
                                        $rejectTotal = resulttotals($Reports,$date,$process_name,$reject_type);
                                        $rejectTotal = (!empty($rejectTotal) ? $rejectTotal : "&nbsp;");

                                        $display .= "<td class=\\"total$border\\" align=\\"right\\">$rejectTotal</td>\\r";

                                        $bor++;
										$rt_running_count++;

										if ($rt_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " border" : '');
	
	                                            $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
                                }
	                            $display .= "<th class=\\"border\\">&nbsp;</th>\\r";
                            }
                        $display .= "</tr>\\r";
                        }
    $display .= "</table>\\r";
}


        if(isset($display)){
            echo "$display";
        }
?>

Thank you so much

Hi,

Is it possible that the all list of reject_acro from reject_list table per process will be displayed per date even it has no reject.

Thank you.

Something like this? Basically we use the same functions that gets the totals by date and we remove the date condition. I left some old code in this page so I looks a little butchered.

<?php
ob_start();
include "connection.php";
/*
Assuming that $id is called by other means but
defined here for testing.  So instead of checking
IF $id is a particular number, we check that it is set
and query for specific week without adjustment in query
*/
$id = "29";

//$id = $_POST['id'];
if(isset($id)){
    /*
    We are building an array of all information with a single query.
    */
    $Reports = array();
   // $dates = array();
   // $process_names = array();
   // $reject_types = array();
   // $compound_types = array();
   // $rejects = array();
   // $reject_total = array();
    $sql = "SELECT
    r.reject_date,
    r.reject,
    r.process_id,
    r.reject_type,
    r.compound_type,
    p.process_name
    FROM op_reject AS r
    JOIN process_list AS p
    ON (p.process_id = r.process_id)
    WHERE WEEK(reject_date) = '$id'
    ORDER BY r.reject_date, compound_type  ASC";
    $res = mysql_query($sql);
    $k=0;
    while($row = mysql_fetch_assoc($res)){
        $Reports[$k]['reject_date'] = $row['reject_date'];
        $Reports[$k]['process_name'] = $row['process_name'];
        $Reports[$k]['reject_type'] = $row['reject_type'];
        $Reports[$k]['compound_type'] = $row['compound_type'];
        $Reports[$k]['reject'] = $row['reject'];
       $k++;
    }

    //| *************************************************** |\\\\
    //| Build functions to return specific values or arrays |\\\\
    //| *************************************************** |\\\\

    // Returns dates array \\\\
    function dates($array){
        $dates = array();
        foreach($array as $k => $v){
            $dates[] = $v['reject_date'];
        }
        $dates = array_unique($dates);
        sort($dates);
        return $dates;
    }

    // Returns process_names array \\\\
    function process_names($array){
        $process_names = array();
        foreach($array as $k => $v){
            $process_names[] = $v['process_name'];
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        return $process_names;
    }

	
    //*****************************************//
       // Returns number of columns by date \\\\
    //*****************************************//
	/*
    function columns($array,$date){
        //process names
        $process_names = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $date){
                $process_names[] = $v['process_name'];
            }
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        // get reject_types by process name
        $reject_types = array();
        foreach($process_names as $process_name){
            foreach($array as $k => $v){
                if ($v['reject_date'] == $date &&
                    $v['process_name'] == $process_name){
                    $reject_types[$process_name][$v['reject_type']] = $v['reject_type'];
                }
            }
        }
        //Convert reject_type to count
        $counts = array();
        foreach($reject_types as $reject_type){
            $counts[] = count($reject_type);
        }
        //return largest value
        $max_count = max($counts);
        return $max_count;
    }
	 */
    //*****************************************//
     // END Returns number of columns by date \\\\
    //*****************************************//

	
    //*****************************************//
       // Returns number of columns by date \\\\
    //*****************************************//
    function columns($array,$date){
        //process names
        $process_names = array();
        foreach($array as $k => $v){
           // if ($v['reject_date'] == $date){
                $process_names[] = $v['process_name'];
           // }
        }
        $process_names = array_unique($process_names);
        sort($process_names);
        // get reject_types by process name
        $reject_types = array();
        foreach($process_names as $process_name){
            foreach($array as $k => $v){
               // if ($v['process_name'] == $process_name){
                    $reject_types[$process_name][$v['reject_type']] = $v['reject_type'];
               // }
            }
        }
        //Convert reject_type to count
        $counts = array();
        foreach($reject_types as $reject_type){
            $counts[] = count($reject_type);
        }
        //return largest value
        $max_count = max($counts);
        return $max_count;
    }
    //*****************************************//
     // END Returns number of columns by date \\\\
    //*****************************************//
	
	
    // Returns compound_type array for process_name \\\\
    function compound_types($array,$process_name){
        $compound_types = array();
        foreach($array as $k => $v){
            if ($v['process_name'] == $process_name){
                $compound_types[] = $v['compound_type'];
            }
        }
        $compound_types = array_unique($compound_types);
        sort($compound_types);
        return $compound_types;
    }

    // Returns reject_type array for date and process_name \\\\
	/*
    function reject_types($array,$reject_date,$process_name){
        $reject_types = array();
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name){
                $reject_types[] = $v['reject_type'];
            }
        }
        $reject_types = array_unique($reject_types);
        sort($reject_types);
        return $reject_types;
    }
	*/
	
	 // Returns reject_type array for process_name \\\\ NEW
    function reject_types($array,$reject_date,$process_name){
        $reject_types = array();
        foreach($array as $k => $v){
            //if ($v['process_name'] == $process_name){
                $reject_types[] = $v['reject_type'];
           // }
        }
        $reject_types = array_unique($reject_types);
        sort($reject_types);
        return $reject_types;
    }

    // Returns reject amount for cell \\\\
    function searchresults($array,$reject_date,$process_name,$reject_type,$compound_type){
        $result = "";
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == "{$reject_date}" &&
                $v['process_name'] == "{$process_name}" &&
                $v['reject_type'] == "{$reject_type}" &&
                $v['compound_type'] == "{$compound_type}"){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns reject total based on $reject_date,$process_name,$reject_type \\\\
    function resulttotals($array,$reject_date,$process_name,$reject_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['reject_type'] == $reject_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

    // Returns compound total based on $reject_date,$process_name,$compound_type \\\\
    function compound_resulttotals($array,$reject_date,$process_name,$compound_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['reject_date'] == $reject_date &&
                $v['process_name'] == $process_name &&
                $v['compound_type'] == $compound_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }
	
	
     //NEW
    // Returns compound total based on $process_name,$compound_type \\\\
    function compound_resulttotalsALL($array,$process_name,$compound_type){
        $total=0;
        foreach($array as $k => $v){
            if ($v['process_name'] == $process_name &&
                $v['compound_type'] == $compound_type){
                $total += $v['reject'];
            }
        }
        $total = ($total!=0 ? number_format($total, 2, '.', '') : '');
        return $total;
    }

//echo "<pre>";
//print_r($Reports);
//echo "</pre>";

////Build display data BEFORE output to browser////
$display = "<table border=0 cellpadding=0 cellspacing=0 class=\\"display\\">
        <thead>
            <tr>
                <th>Compound</th>\\r";
                //I'll keep your id identifier in place
                $i=1;
                $dates = dates($Reports);
                foreach($dates as $date){
                    //We'll run our columns function in our date loop to get column count
                    $cols = columns($Reports,$date);

                    $display .= "<th id=col".$i." colspan=\\"$cols\\" class=\\"border\\">$date</th>\\r";
            		$display .= "<th>&nbsp;</th>\\r";

                    $i++;
                }
				 	//NEW
            		$display .= "<th class=\\"border\\">TOTAL</th>\\r";
            $display .= "</tr>
            </thead>";

                $process_names = process_names($Reports);
                foreach($process_names as $process_name){
                    $display .= "<tr>\\r";
                        $display .= "<td>$process_name</td>\\r";

                    foreach($dates as $date){
                           $bor=0;
                        $reject_types = reject_types($Reports,$date,$process_name);
                        $reject_type_count = count($reject_types);
                        $type_for_date = (!empty($reject_types) ? "true" : "false");
                        $cols = columns($Reports,$date);

                        if ($type_for_date == "false"){
                            for($c=0;$c<$cols;$c++){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>&nbsp;</td>\\r";

                                $bor++;
                            }
                        }else{
							$rt_running_count=0;
                            foreach($reject_types as $reject_type){
                                $border = ($bor==0 ? " class=\\"border\\"" : '');

                                $display .= "<td$border>$reject_type</td>\\r";

                                $bor++;
								$rt_running_count++;
                            }
							if ($rt_running_count==$reject_type_count){
	                            for($d=$reject_type_count;$d<$cols;$d++){
	                                $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                $display .= "<td$border>&nbsp;</td>\\r";
	
	                                $bor++;
	                            }
							}
                        }
            		$display .= "<td class=\\"border\\">Total</td>\\r";
                    }
	            $display .= "<th class=\\"border\\">WEEK</th>\\r";
            $display .= "</tr>\\r";
                $compound_types = compound_types($Reports,$process_name);
                        foreach($compound_types as $compound_type){
                            $display .= "<tr>\\r";
                                $display .= "<td>$compound_type</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');

                                        $display .= "<td$border>&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
								
									$ct_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " class=\\"border\\"" : '');
                                        $reject = searchresults($Reports,$date,$process_name,$reject_type,$compound_type);
                                        $reject = (!empty($reject) ? $reject : "&nbsp;");

                                        $display .= "<td$border align=\\"right\\">$reject</td>\\r";

                                        $bor++;
										$ct_running_count++;
										
										if ($ct_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " class=\\"border\\"" : '');
	
	                                            $display .= "<td$border>&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
									
                                        $compoundTotal = compound_resulttotals($Reports,$date,$process_name,$compound_type);
                                        $compoundTotal = (!empty($compoundTotal) ? $compoundTotal : "&nbsp;");

                                        $display .= "<td class=\\"total border\\" align=\\"right\\">$compoundTotal</td>\\r";
                                }
                            }
                                        $compoundTotalALL = compound_resulttotalsALL($Reports,$process_name,$compound_type);
                                        $compoundTotalALL = (!empty($compoundTotalALL) ? $compoundTotalALL : "&nbsp;");

                                        $display .= "<td class=\\"total border\\" align=\\"right\\">$compoundTotalALL</td>\\r";
            $display .= "</tr>\\r";
                        }

           //---total rejects per process and per reject type---//
                        $display .= "<tr>\\r";
                        $display .= "<td class=\\"total\\">Total</td>\\r";

                            foreach($dates as $date){
                                $bor=0;
                                $reject_types = reject_types($Reports,$date,$process_name);
                                $reject_type_count = count($reject_types);
                                $type_for_date = (!empty($reject_types) ? "true" : "false");
                                $cols = columns($Reports,$date);
                                 if ($type_for_date == "false"){
                                    for($c=0;$c<$cols;$c++){
                                        $border = ($bor==0 ? " border" : '');

                                        $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";

                                        $bor++;
                                    }
                                }else{
									$rt_running_count=0;
                                    foreach($reject_types as $reject_type){
                                        $border = ($bor==0 ? " border" : '');
                                        $rejectTotal = resulttotals($Reports,$date,$process_name,$reject_type);
                                        $rejectTotal = (!empty($rejectTotal) ? $rejectTotal : "&nbsp;");

                                        $display .= "<td class=\\"total$border\\" align=\\"right\\">$rejectTotal</td>\\r";

                                        $bor++;
										$rt_running_count++;

										if ($rt_running_count==$reject_type_count){
	                                        for($d=$reject_type_count;$d<$cols;$d++){
	                                            $border = ($bor==0 ? " border" : '');
	
	                                            $display .= "<td class=\\"total$border\\">&nbsp;</td>\\r";
	
	                                            $bor++;
	                                        }
										}
                                    }
                                }
	                            $display .= "<th class=\\"border\\">&nbsp;</th>\\r";
                            }
							//NEW
            		$display .= "<th class=\\"border\\">TOTAL</th>\\r";
                        $display .= "</tr>\\r";
                        }
    $display .= "</table>\\r";
}


        if(isset($display)){
            echo "$display";
        }
?>

Hi Drummin,

Thank you for helping me on my problem in displaying of rejects report.
I need your help again if it is possible to display all the list of rejects acro on the header even it has no rejects, to be the layout inline. and also We need to add additional column after of the last date like this:

the new layout should be:

Compound ------2013-07-22-------2013-07-23--------2013-07-24-----2013-07-25----so on-------Week 29–
Compound Mixing ----list of all reject acro---------------------------------------------------------list of reject acro
P28-------------per process-----------------------------------------------------------------------total per reject acro
P35
P41
Total
Final Mix----list of all reject acro
P28-------------per process—
P35
P41
P45
Total
Extrusion----list of all reject acro
P28-------------per process—
P35
P41
P45
P47
Half Shell ------2013-07-22-------2013-07-23--------2013-07-24-----2013-07-25----so on-------Week 29
Forming ----list of all reject acro----------------------------------------------------------------list of reject acro
P28-------------per process--------------------------------------------------------------------total per reject acro
P35
P41
Total
Deflashing----list of all reject acro
P28-------------per process—
P35
P41
P45
Total
HS/BD----list of all reject acro
P28-------------per process—
P35
P41
P45
P47
Core ------2013-07-22-------2013-07-23--------2013-07-24-----2013-07-25----so on-------Week 29
Core Molding ----list of all reject acro---------------------------------------------------------list of reject acro
P28-------------per process------------------------------------------------------------------total per reject acro
P35
P41
Total
Core Buffing----list of all reject acro
P28-------------per process—
P35
P41
P45
Total
Core Solution----list of all reject acro
P28-------------per process—
P35
P41
P45
P47

I hope you can help on this and I also tried my best to do it. i will inform you on the progress if i made it.

Thank you for helping me. I appreciate it.

I also attached the output of new code you given.

Thank you so much for your help

Doesn’t my last version do what you’re asking, with totals of each compound in far right column for the week.

Hi,

The total per date that you add is correct.

The week total should also per reject type.

Look at my thread #33

Thank you so much Drummin

Correct me if I’m wrong but reject_types are listed in vertical columns for each week and so there is no point of reference to display in the right column. We show totals under each of these columns for reject_type. The compound process type P28 etc. is listed in each row and so those totals are show in the far right column.

reject type or reject acro are the S-SC-SP-SH and so on and compound are P28, P35, P41 etc… We need to total or sum all rejects per reject acro and compound for that week.

for example SUM all SC rejects of P28.

SuM all rejects per reject acro per compound

We just summarize or summarize the daily to week.

Thank you so much

So the WEEK TOTALS area is not a single column but a group of columns like shown for each week and the totals for S-SC-SP-SH etc for the week should be shown in each corresponding column, correct? Otherwise there is no reference to for example reject acro “SC” in the right column.

Sample:
-----------------2013-07-22-2013-07-23–2013-07-24–2013-07-25-----2013-07-26—2013-07-27----2013-07-28------Week 29
Core Molding–BS-C-total–SP-SH-total–TH–T-total–WS–SH–total–BS–C–total–SP–SH-total—T–TH–SS-total----BS—C–SP–SH—TH–T–WS–SS
P28------------ 1—2-3-----4—5----9-----6----7-13----8----9----17----10–11-21----12–13–25----14–15-------29------11—13-16–18----21–21–8------

also the reject acro that has no reject will also displayed on the total weeks list
I hope this sample can help you to figured out.

Thank you so much