insert form wizard: how to concatenate two fields into one?

Any tips and tricks that has to with the ADDT that doesn't fit into one of the other categories
antonio
Posts: 77
Joined: 2010-09-28 11:48

insert form wizard: how to concatenate two fields into one?

Post by antonio » 2011-03-08 12:12

Hi all,
I have an insert form on a page and I have two fields that allow the user to enter a number (set as varchar in the db) and a decimal (set as varchar in the db).
I need to concatenate those two fields into one in the "number,decimal" format; then, I need to insert this field in his db field.

Is there a way to do this with ADDT?
Or, is there a way toworkaround this problem in another way? basically I need to force the user to enter the number with 2 decimals.

examples:
these are values that will be accepted:
100,20
12,50
3,50
1000,50

thesen are values that will not be accepted:

100,2
12,5
3
1000

Is there a solution?

TIA

antonio

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: insert form wizard: how to concatenate two fields into o

Post by Fred » 2011-03-09 17:52

Hi Antonio,
Quick question... Why do you store the data in separate fields and as varchar?

I would simply go for float(6.2) or whatever you want it to be.
Then when the user enters the data it is irrelevant if he enters 3 or 3.00. The data in the db will always be properly formatted.

Now when you want to display the data you might end up with 3 instead of 3.00 but you can format the value with php
<?php echo number_format($row_rs_cur_tot['cur_hrs'],2); ?>

jlig
Posts: 35
Joined: 2010-07-09 16:17

Re: insert form wizard: how to concatenate two fields into o

Post by jlig » 2011-05-06 17:46

I always use Decimal for storing Dollar amounts in MySQL.. (Type = Decimal) (Length = 10,2)

- See this link for a good description & image: http://jeffmigliore.com/

Post Reply