Jump to content

[SOLVED] 2 digits to the left of decimal not showing up


jaxdevil

Recommended Posts

Ok, I have my script one step from being done, in one of the scripts it is pulling up the data in a loop, adding up the values, and displaying them, but the sum (the part where it adds it up) is not displaying the cents... the actual row does in the loop, but when it adds all the amount fields from the rows from the loop that part only displays the dollar amount if the cents part are both zeros.  So if it is $0.19 that displays correctly (I am not using the dollar symbol on the output though)  but if it is $10.00 it just displays the number 10, no decimal, no dots afterwards. Here is the code I am using, PLEASE help...

 

<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}
$sum = array_sum($sum);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum;
?>

Link to comment
Share on other sites

Thanks again Raj!

 

I am lost on where to insert that at. I literally am on hour 28 and I can literally barely think. If you get a free chance can you show me where/how to insert that? I appreciate all the help you have been through this project!

 

SK

Link to comment
Share on other sites

here you go, this should work tell me if you have any problems 

 

<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}
$sum = number_format(array_sum($sum),2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.