kevinfwb Posted January 25, 2007 Share Posted January 25, 2007 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.57I'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 More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 try number format()? Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168715 Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 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? Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168716 Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 What have you tried?Ken Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168717 Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 I edited my last post if you haven't re-read it. I've also triedecho " <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. Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168720 Share on other sites More sharing options...
corbin Posted January 25, 2007 Share Posted January 25, 2007 echo "<td><div align=\"center\">" . number_format(,"{$row['mr20']}",,2) . "</div></td>\n";Should work :p Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168728 Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 Parse error: syntax error, unexpected ',', expecting ')' in ...... Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168731 Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 You don't need the "{ }" inside the function:[code]<?phpecho '<td><div align="center">' . number_format($row['mr20'],2) . "</div></td>\n";?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168742 Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 That was it, I really appreciate your help.-Kevin Link to comment https://forums.phpfreaks.com/topic/35622-money_format-inside-an-html-table/#findComment-168744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.