hey guys!
Is there a way to enter $ sign in database because I am trying to set a column called fees and set it to INT but must I do this manually with the dollar sign as
echo ‘$’.$user_fees;
something like that…
hey guys!
Is there a way to enter $ sign in database because I am trying to set a column called fees and set it to INT but must I do this manually with the dollar sign as
echo ‘$’.$user_fees;
something like that…
You want to not store money values with a dollar sign. Doing so will negate the benefit of being able to do mathematical operations in your queries and make uneccessary work for PHP. Store them as decimal instead of having PHP remove the dollar sign, do the math, and add the dollar sign back on.
INT means integer so it can’t contain any letters, symbols or decimals, just pure whole numbers.
For currency I would use Decimal as that can account for dollars and cents, though you could use int to store values in cents or whole dollars if you don’t deal in cents.
Decimal is still a purely numeric format (no letters or symbols), which is the correct approach, as you want to be storing a value. The currency the value relates to may be stored elsewhere, like another column or look-up-table. If you only ever deal in dollars you don’t even need that, you just know it’s dollars.
If you do deal in different currencies, don’t use the dollar symbol to define a currency, as that is ambiguous, it could mean US Dollar, Australian Dollar, or any other country that uses dollars which are not necessarily the same value or currency. Instead use recognised currency codes like USD
etc.
Thanks guys for the suggestions… I guess that I can always echo out the dollar sign with the corresponding int value…
Yes, if it’s always going to be in dollars it can be in your template, eg:
<p>Price: $<?= $price ?></p>
Or you may use a function like money_format
By storing the value as a number as opposed to a string, you are able to use mathematical functions to process/order your values. Eg, calculate tax/discounts, sum totals, order/select by price, select price ranges, convert to other currencies etc…
It is far more versatile and useful.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.