This may be a stupid question. PHP is not my strong suit. I'm trying to put a total at the bottom of a query result w/ no success. It wasn't working so I added in a running total to see where it hung up. This example works fine but doesn't format properly:
$grand = 0;
while (odbc_fetch_into($result,$myrow))
{
$city = $myrow[0];
$state = $myrow[1];
$total =$myrow[2];
$grand = $grand + $total;
echo "<tr><td>$city</td><td>$state</td><td>$total</td><td>$grand</td></tr>";
}
The goal was to have all of the totals in a money format. I changed the pull like this:
$grand = 0;
while (odbc_fetch_into($result,$myrow))
{
$city = $myrow[0];
$state = $myrow[1];
$total =number_format($myrow[2],2);
$grand = $grand + $total;
echo "<tr><td>$city</td><td>$state</td><td>$total</td><td>$grand</td></tr>";
}
But this isn't working. With the running total, it appears that when it hits an amount over 1000, it takes what's before the comma... ex: It added up nicely through the first ten rows or so, then it hit an amount just over 12,000, and only added in 12 dollars.
--------------------
I just about posted this then an idea beat me on the back of my head. I'm more of a SQL guy, so I converted this to varchar before sending to PHP and it works like I'd planned, but now my curiosity is peaked. Can this be achieved in PHP? The format would arrive to the page w/ 4 places after the decimal point. How would one make these show up w/ 2 decimal places and total properly?
Again forgive my ignorance if this is blatantly simple. Thanks, all.
$grand = 0;
while (odbc_fetch_into($result,$myrow))
{
$city = $myrow[0];
$state = $myrow[1];
$total =$myrow[2];
$grand = $grand + $total;
echo "<tr><td>$city</td><td>$state</td><td>$total</td><td>$grand</td></tr>";
}
The goal was to have all of the totals in a money format. I changed the pull like this:
$grand = 0;
while (odbc_fetch_into($result,$myrow))
{
$city = $myrow[0];
$state = $myrow[1];
$total =number_format($myrow[2],2);
$grand = $grand + $total;
echo "<tr><td>$city</td><td>$state</td><td>$total</td><td>$grand</td></tr>";
}
But this isn't working. With the running total, it appears that when it hits an amount over 1000, it takes what's before the comma... ex: It added up nicely through the first ten rows or so, then it hit an amount just over 12,000, and only added in 12 dollars.
--------------------
I just about posted this then an idea beat me on the back of my head. I'm more of a SQL guy, so I converted this to varchar before sending to PHP and it works like I'd planned, but now my curiosity is peaked. Can this be achieved in PHP? The format would arrive to the page w/ 4 places after the decimal point. How would one make these show up w/ 2 decimal places and total properly?
Again forgive my ignorance if this is blatantly simple. Thanks, all.