Jump to content

money_format inside an HTML table


kevinfwb

Recommended Posts

Hello - I have a PHP script that outputs the values from a MySQL database.  The code works as needed aside from the numeric formatting.

For example, the value of a field is 1234.567 (I used 3 digits because of how it is calculated and compounded)

I would like to format the output to be $1,234.57

I've tried using both the number_format money_format, however, I can not get the syntax right.  I usually get an error or the actual output shows the code depending on the syntax I'm using.

Here is a code snippet that I am working with.

echo "  <tr>\n";
echo "      <td><div align=\"left\"></div></td>\n";
echo "    <td><div align=\"center\">{$row['ar18']}</div></td>\n";
echo "    <td> </td>\n";
echo "  </tr>\n";


Thank you for your time - Kevin
Link to comment
https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/
Share on other sites

Sorry, I should have clarified a bit.  It's not that I can't get the syntax of formatting it correctly.

If I just echo number_format($variable,2); I get the right formatting.

What I am having trouble with is the combination of number_format and the HTML in the same echo statement. 

echo "    <td><div align=\"center\">format_number( {$row['ar18']} ,2) </div></td>\n";
Throws an error as well as all variations that I've tried so far.


Did that make any sense?
I edited my last post if you haven't re-read it.  I've also tried

echo "    <td><div align=\"center\">",number_format(,"{$row['mr20']}",,2)"</div></td>\n";

and some other variations.. all throwing an error.  I'm realtively new to PHP/MySQL most of everything I've done so far is by using a piece by piece trial and error method.  This is just stumping me.  As I said I can get it to work with a standard echo, just not within the html table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.