Took your suggestion and used array_map to call a number_format function
before printing. This displays the integer data just the way I want. However, as
part of the final display, I add two numbers together for each column to get a
total using the formatted data as a base. The totals are now sums of the
truncated versions (with the comma as the demarcation point) of the formatted
numbers.
Code: Select all
function fmt($f) {
return number_format($f,0);
}
for ( $n = 0; $n < $numrows; $n++ ) {
$fld = mysql_num_fields($r2);
$row2 = array_map("fmt", mysql_fetch_row($r2));
$row3 = array_map("fmt", mysql_fetch_row($r3));
$land .= '<td align="right">' . implode('</td><td align="right">', $row2) . '</td></tr>';
echo '<tr><td align="right">' . mysql_result($r1,$n,"PIN") . '</td><td bgcolor="yellow">' . mysql_result($r1,$n,"Name") . '</td></tr>';
echo '<tr><td><br></td><td>Land</td>' . $land;
$bldg .= '<td align="right">' . implode('</td><td align="right">', $row3) . '</td></tr>';
echo '<tr><td><br></td><td>Buildings</td>' . $bldg;
for ( $j=0; $j < $fld; $j++ ) {
$sline .= '<td align="right">------------</td>';
$tot .= '<td align="right">' . ($row2[$j] + $row3[$j]) . '</td>';
$dline .= '<td align="right">========</td>';
}
I realize that I am using formatted data to perform an 'add' and this is the probable cause
of the problem i.e. comma acting as a decimal point. However, I want to slim the code as
much as possible. Can this be done in this or some other fashion without having to create
other variables just to hold the formatted data while using the raw mysql_fetch_row to
perform the math addition?