// set the last_host if we are just beginning if (($first_record==true)){ $last_host=$row["host_name"]; $last_port=$row["port_number"]; $first_record=false; } // test to see if we need to print the first_header if (($first_header == true)) { echo ''; echo 'Host Name/IP'; echo 'Ingress Bytes'; echo 'Total In GB'; echo 'Egress Bytes'; echo 'Total Out GB'; echo 'Difference'; echo 'Port'; echo ''; // we have printed it so now regular header and the first header are false // header will move b etween true and false as we go through the loop $header=false; // first_header will remain false as we go throught the loop $first_header=false; } // test to see if we need to print the header (first_header set this false on first loop) if (($header == true)) { echo ''; echo 'Host Name/IP'; echo 'Ingress Bytes'; echo 'Total In GB'; echo 'Egress Bytes'; echo 'Total Out GB'; echo 'Difference'; echo 'Port'; echo ''; // we have printed it so now regular header is false $header=false; } // set test_host $test_host=$row["host_name"]; // set test port $test_port=$row["port_number"]; // if the last one tested is the same as this one if ($last_host == $test_host){ // set the port change status if ($last_port == $test_port){ // set same_port true $same_port=true; // set the last_port $last_port=$row["port_number"]; } else { // set same_port false $same_port=false; // set the last_port $last_port=$row["port_number"]; $tot_port=$last_port; } // set same_host to tru $same_host=true; // add to the running total for existing host $in = ($in + $row["in_bytes"]); $out = ($out + $row["eg_bytes"]); $diff = (max($in,$out) - min($in,$out)); // add up running totals to the end totals for the host $in = ($in + $row["in_bytes"]); $out = ($out + $row["eg_bytes"]); $diff = (max($in,$out) - min($in,$out)); // transfer totals to gt for later use $tot_in=$in; $tot_out=$out; $tot_diff=$diff; // printing occurs if port changes same_port=false // zero grand total counters $in=$out=$diff=0; } else { // if the test_host is not the same then we have to print out the grand total and reset // set same_host false ( later logic calls for the total printout) $same_host=false; // set same port to false $same_port=false; // zero the grand total counters $in=$out=$diff=0; // add to the running total for this new host $in = ($in + $row["in_bytes"]); $out = ($out + $row["eg_bytes"]); $diff = (max($in,$out) - min($in,$out)); // set last_port $last_port = $row["port_number"]; $tot_port=$last_port; } if (($same_host == false) || ($same_port==false)){ // print out the line and totals echo ''; echo '' . $last_host . ''; echo '' . $tot_in . ''; echo '' . number_format(($tot_in/1000000000),4) . ' G'; echo '' . $tot_out . ''; echo '' . number_format(($tot_out/1000000000),4) . ' G'; echo '' . number_format(($tot_diff/1000000000),4) . ' G'; echo '' . $tot_port . ''; echo ''; // increment the line counter to print header when we change pages at line 25 (($ctr++)); // set the header printing flag to true if the counter is exceeded //if($ctr > 25){ // $header=true; //} } else { // set the last_host and last_port as we leave this loop // set last_host $last_host=$row["host_name"]; // set last_port $last_port=$row["port_number"]; }