Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > mySQL - putting a comma in a number field??

mySQL - putting a comma in a number field??
Thread Tools
Mac Elite
Join Date: May 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Aug 25, 2003, 08:10 AM
 
Hey guys!! (excuse me if there are any ladies in the web dev forum, I don't think there is)

I have a slight problem. I am making a website for a real estate company - this is the first database site I have ever done.

In the price field, the database only wants numbers. Fair enough, I have set it to print a $ out the front of any price anyway.

But I need the comma's for the thousands! A house selling for $500,000 is much easier to read than $500000.

If I put a comma into the price field, it doesn't like it. I don't mind if the comma isn't in the database itself, but when it displays on the screen I really need it to put them in the right spots. Any ideas?

Sample here:
http://www.kenbucklandrealestate.com...erty.php?ID=30

(price is down the bottom)

Any suggestions at all are welcome! Using php and mysql at the moment.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Aug 25, 2003, 08:57 AM
 
Originally posted by thePurpleGiant:
If I put a comma into the price field, it doesn't like it. I don't mind if the comma isn't in the database itself, but when it displays on the screen I really need it to put them in the right spots. Any ideas?
PHP will do this for you with a number formatter (number_format). Something like this:

[php]
$total=123456789.12345;
$total="$".number_format($total, 2,'.',',');
$total will be a string formated as '$123,456,789.12'
[/php]

Read here for more info:

http://www.php.net/manual/en/function.sprintf.php
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Aug 25, 2003, 10:20 AM
 
Yes; store it without, and put it in using PHP.
[Wevah setPostCount:[Wevah postCount] + 1];
     
Mac Elite
Join Date: May 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Aug 26, 2003, 02:27 AM
 
Thank you!!!!

http://www.kenbucklandrealestate.com...erty.php?ID=38

^^My house^^ (with comma's - gotta ditch the decimal tho...)

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:20 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2