// set up the first pass through
if ($first_test=true){
// set first_test false hereafter
$first_test=false;
// set last_host
$last_host=$row["host_name"];
// set last_port
$last_port=$row["port_number"];
// set test_host
$test_host=$row["host_name"];
// set test port
$test_port=$row["port_number"];
} else {
$test_host=$row["host_name"];
$test_port=$row["port_number"];
}
// test port and host to see if they are the same if so just total
if (($last_host == $test_host) && ($last_port==$test_port)){
echo '
| LH and LP'. $last_host . ' ' . $test_host .' |
';
// 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));
}
// if either host or port are different print out the totals
if ($last_host != $test_host){
echo '| LHnotTH'. $last_host . ' ' . $test_host .' |
';
// transfer running totals to grand totals for this port
$tot_in=$in;
$tot_out=$out;
$tot_port=$last_port;
$tot_host=$last_host;
// print out the line and totals
echo '';
echo '| ' . $tot_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 '
';
}
if ($last_port != $test_port){
echo '| LPnotTP'. $last_host . ' ' . $test_host .' |
';
// transfer running totals to grand totals for this port
$tot_in=$in;
$tot_out=$out;
$tot_port=$last_port;
$tot_host=$last_host;
// print out the line and totals
echo '';
echo '| ' . $tot_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 '
';
}
// set last_host and last_port to this record
// set test_host
$last_host=$row["host_name"];
// set test port
$last_port=$row["port_number"];