Forum Moderators: coopster

Message Too Old, No Replies

can'r gert the print table aligned right

         

ckdoublenecks

6:37 pm on Apr 17, 2011 (gmt 0)

10+ Year Member



The below code works correctly except that the totals don't align correctly on the page and the totcharges doesn't display the decimals. Can someone tell me what I'm doing wrong?
<?php
mysql_connect(localhost,root,"");
mysql_select_db(oodb) or die( "Unable to select database");
$query=" SELECT * FROM oocust WHERE payrec = 'R' AND pd = ' '";
$result=mysql_query($query);
$num=mysql_numrows($result);
echo date("m/d/Y") . "<br />";
echo "<font size=+2><b> Old Orchard Plumbing Invoices Due Report</font></b></b><br />";
echo "<table cellspacing=1 cellpadding=0 border=0>
<tr>
<th colspan=2></th>
<th align=left>order</th>
<th colspan=5></th>
<tr>
<th>Inv#</th>
<th>Customer</th>
<th align=left>date</th>
<th>days late</th>
<th align=right>Charges</th>
<th align=right>tax</th>
<th align=right>Owed</th>
<tr>
<TH colspan=11>=======================================================================</TH>
</tr>";
while($row = mysql_fetch_array($result))
{
// $charges=$row['charges'];
// $tax=$row['tax'];
// $amtdue=$row['amtdue'];
$totcharges = $totcharges + $row['charges'];
$tottax = $tottax + $row['tax'];
$totamtdue = $totamtdue + $row['amtdue'];
echo "<tr>";
echo "<td>" . $row['invnum'] . "</td>";
echo "<td>" . $row['bname'] . "</td>";
echo "<td>" . $row['dateord'] . "</td>";
echo "<td align=right>" . $row['dayslate'] . "</td>";
echo "<td align=right>" . $row['charges'] . "</td>";
echo "<td align=right>" . $row['tax'] . "</td>";
echo "<td align=right>" . $row['amtdue'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table cellspacing=1 cellpadding=0 border=0>
<tr>
<tr>
<TH colspan=11>=======================================================================</TH>
</tr>";
echo "<tr>";
echo "<td>Totals Due</td>";
echo "<td>.</td>";
echo "<td>.</td>";
echo "<td>.</td>";
echo "<td>.</td>";

echo "<td align=right>$totcharges</td>";
echo "<td align=right>$tottax</td>";
echo "<td align=right>$totamtdue</td>";
echo "</tr>";
echo "</table>";
mysql_close();
?>

rocknbil

6:07 pm on Apr 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<tr>
<th colspan=2></th>
<th align=left>order</th>
<th colspan=5></th>
<tr>

Adds up to 8. Then after this line,

$totamtdue = $totamtdue + $row['amtdue'];

I count 7 columns. Then the new table has

<TH colspan=11>

Followed by another row of 8.

These will never align, you need it all in one table with equal number of cells. When in doubt with tables, add a border to the table and the miscounts will be very obvious.

totcharges doesn't display the decimals.


$totalcharges=sprintf("%.2f",$totalcharges);

Or do it inline.

echo "<td align=right>" . sprintf("%.2f",$totalcharges) . "</td>";

ckdoublenecks

7:14 pm on Apr 18, 2011 (gmt 0)

10+ Year Member



Thanks, fellows for the input. I'm printing all records (which match my selector) into one table, then printing totals into another. I know this will never align. What I need is to know how to print the totals so that they will align.

ckdoublenecks

7:41 pm on Apr 18, 2011 (gmt 0)

10+ Year Member



I meant to ask, why do I need to do the sprintfto that totcharges field (total of charges field) and not others? I'm having the same thing happen in another program using the charges field?