Hello Kevin,
You are such a genius. I do not know how you knew it but yup you are correct. It is an XY problem.
If you allow me to explain.
I manage to get a slicer below
[php]
foreach(array_keys($array) as $key) {
unset($array[$key][1]);
}
[/php]
This actually slice the whole row of an array but my issue is the column number. It change every time I slice the array. Always getting this undefined offset.
I am getting nowhere. Below was my code using array:
[php]
$NGTable = Array();
$date_to1 = new DateTime(‘11/08/2016 00:00:00’);
$date_from1 = new DateTime(‘11/07/2016 00:00:00’);
$date_from = $date_from1->format(‘Y-m-d’);
$date_to = $date_to1->format(‘Y-m-d H:i:s’);
$result1 = mysqli_query($con,“SELECT * FROM lot WHERE date_create BETWEEN ‘$date_from%’ and ‘$date_to%’”);
if(! $result1){ echo “Line Number:” . LINE ; die('Cannot query error: ’ . mysqli_error($con)); }
//$result = mysqli_fetch_array($result1);
$LotIDMaxRow = mysqli_num_rows($result1);
//Need to get the max number of item in no_good
//echo count($result);echo “
”;
$MaxNGFetch = mysqli_fetch_array(mysqli_query($con,“SELECT MAX(id) FROM no_good”));
$MaxNG = $MaxNGFetch[‘MAX(id)’];
$row=1;
$ColSum = Array();
for ($col = 0; $col < $MaxNG+1; $col++) {
$ColSum[$col] = 0;
}
$NGTable[0][0] = “LOT”;
for ($col = 1; $col < $MaxNG+1; $col++) {
$query = mysqli_fetch_array(mysqli_query($con,“SELECT * FROM no_good WHERE id=$col”));
$NGTable[0][$col]=$query['ng_name'];
}$NGTable[0][$col+1] = “TOTAL”;
while ($LotID = mysqli_fetch_array($result1)) {
$RowSum = 0;
for ($col = 0; $col < $MaxNG+1; $col++) {
if ($col == 0){
$NGTable[$row][$col] = $LotID[‘proc’].$LotID[‘petsa’].str_pad($LotID[‘serye’], 3, ‘0’, STR_PAD_LEFT);
} else {
$NGQuery = mysqli_fetch_array(mysqli_query($con,“SELECT SUM(qty) FROM ng_logs
WHERE lot_id={$LotID[‘lot_id’]} AND ng_id=$col”));
if(! $NGQuery){ echo “Line Number:” . LINE ; die('Cannot query error: ’ . mysqli_error($con)); }
if($NGQuery[‘SUM(qty)’] === null){
$NGTable[$row][$col] = 0;
} else {
$NGTable[$row][$col] = $NGQuery[‘SUM(qty)’];
$RowSum += $NGQuery[‘SUM(qty)’];
$ColSum[$col] += $NGQuery[‘SUM(qty)’];
}
}
}
$NGTable[$row][$col] = $RowSum;
$row += 1;
}
$NGTable[$row][0] = “Total”;
//Adding the total below the table
$col=1;
$ColSumTot = array_slice($ColSum,1);
foreach($ColSumTot as $key) {
$NGTable[$row][$col] = $key;
$col++;
}echo “
”;
//Need to slice the array.
foreach(array_keys($NGTable) as $key) {
unset($NGTable[$key][1]);
}
//Time to create the table since our array is ready.
echo ‘’;
foreach( $NGTable as $NGTableShow )
{
echo ‘’;
foreach( $NGTableShow as $key )
{
echo ‘’;
}
echo '</tr>';
}
echo ‘
’;
[/php]
Then I read again your message and focus on this word " wrong approach ". A sip of hot coffee and deleted my whole code
Rewriting again my code with a Different approach. I drop the 2d array I was dreaming and woke up to the reality of PHP, HTML and Array(not 2d).
Below was the correct code
[php]
$NGTable = Array();
$date_to1 = new DateTime(‘11/08/2016 00:00:00’); // This was changed.
$date_from1 = new DateTime(‘11/07/2016 00:00:00’); // This was changed.
$date_from = $date_from1->format(‘Y-m-d’);
$date_to = $date_to1->format(‘Y-m-d H:i:s’);
//update start here.========================================
//need to check which LTS has Reject
$NGTitleQuery = mysqli_query($con,“SELECT no_good.id as ngid, no_good.ng_name as ngname FROM lot
JOIN ng_logs ON lot.lot_id=ng_logs.lot_id
JoIN no_good ON ng_logs.ng_id=no_good.id
WHERE date_create BETWEEN ‘$date_from%’ and ‘$date_to%’
GROUP BY ngid”);
if(! $NGTitleQuery){ echo “Line Number:” . LINE ; die('Cannot query error: ’ . mysqli_error($con)); }
$NGNameArray = array();
while($row = mysqli_fetch_array($NGTitleQuery)) {
$NGNameArray[] = $row;
}
//Creating the table
$ColSum = Array();
$col = 1;
//The headers
echo “”;
foreach($NGNameArray as $NGName){
echo “”;
$ColSum[$col] = 0;
$col++;
}
echo “”;
//Now create the table body
$LotQuery = mysqli_query($con,“SELECT * FROM lot WHERE date_create BETWEEN ‘$date_from%’ and ‘$date_to%’”);
while($LotFetch = mysqli_fetch_array($LotQuery)) {
$NGTotalRow = 0;
$col = 1;
$LotNum = $LotFetch[‘proc’].$LotFetch[‘petsa’].str_pad($LotFetch[‘serye’], 3, ‘0’, STR_PAD_LEFT);
echo “
”;
foreach($NGNameArray as $NGName){
$NGQty = mysqli_fetch_array(mysqli_query($con,“SELECT SUM(qty) FROM ng_logs
WHERE lot_id={$LotFetch[‘lot_id’]} AND ng_id={$NGName[‘ngid’]}”));
echo “";
$NGTotalRow += $NGQty[‘SUM(qty)’]; // This accumulate the total per row.
$ColSum[$col] += $NGQty[‘SUM(qty)’];
$col++;
} echo “”; //Display total per row.
}
echo “”;
$col=1;
foreach($ColSum as $key) {
echo “”;
$col++;
}
echo “”;
echo “
LOT |
” . $NGName[“ngname”]. “ |
Total |
$LotNum |
”.$NGQty[‘SUM(qty)’]." |
$NGTotalRow |
Total |
$key |
”;
[/php]
I also attached the output of with 2d array and no 2d array.
Once again. Thank you very much!!! You just simply inspired me.

