##### Formatting Height
• 2011/1/22 0:39

• Friend of XOOPS

• Posts: 323

• Since: 2004/8/6 2

I am trying to enter Height do you know how I can get the input to except 5' 4" and what the database table Type would be?
Arowana

##### Re: Formatting Height
• 2011/1/22 1:00

• XOOPS is my life!

• Posts: 2335

• Since: 2004/11/20

I think you are going to need to write a PHP script that takes the value of the the 'feet' field, multiplies it by 12 and adds it to the 'inches' field to create a single value, e.g. 64 inches. Then reverse the function for output.

If you use TINYINT (unsigned) in MySQL you can store a positive value of 255, which gives you a range up to 21 feet. SMALLINT (unsigned) would allow over 5,000 feet.
A thread is for life. Not just for Christmas.

##### Re: Formatting Height
• 2011/1/22 1:06

• Friend of XOOPS

• Posts: 323

• Since: 2004/8/6 2

ouch I was hopeing to just have a way to format it in the database as 5' 2"

Arowana

##### Re: Formatting Height
• 2011/1/22 1:11

• Moderator

• Posts: 11251

• Since: 2004/4/23

There is one example here of what Peekay suggests:

``` Here's a simple function to convert someone's height in inches to a feet/inch ratio using explode(): function get_height(\$inches) {   //divide by 12 to get inches   \$feet = \$inches/12;   //round decimal so we can divide by 100 and use as percent   \$feet = round(\$feet, 2);   // separate whole from decimal   \$parts = explode(".", \$feet);   \$whole_feet = \$parts[0];   //turn remaining into percent of 12   \$remaining_inches = round((\$parts[1]/100)*12);   \$height = \$whole_feet."' ".\$remaining_inches.""";   return \$height; } ```

Or you can use just text field
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

##### Re: Formatting Height
• 2011/1/22 1:22

• XOOPS is my life!

• Posts: 2335

• Since: 2004/11/20

That function takes an inches value and converts it into feet and inches... which is cool, but I suspect the input will be from two fields, feet and inches?

Get the feet field value from the form (make sure it's a number) then multiply it by 12. Then get the inches field (make sure it's a number between 1 and 12). Add the two together.

Or... just create two database fields per record, height_feet and height_inches (make sure they are numbers)

Or... as Mamba suggests, use a text field.
A thread is for life. Not just for Christmas.

##### Re: Formatting Height
• 2011/1/22 1:31

• Moderator

• Posts: 11251

• Since: 2004/4/23

I think, a text field will be the easiest.

Unless he wants to have two numeric fields, one for feet and the second for inches, so he can manipulate them, if needed
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

##### Re: Formatting Height
• 2011/1/22 1:35

• XOOPS is my life!

• Posts: 2335

• Since: 2004/11/20

Sorry Mamba, we crossed posts there I think! I agree 2 numeric fields is probably best.

It sounds like a simple enough task, but it depends whether or not you want to stop someone entering 9 foot 14 inches.
A thread is for life. Not just for Christmas.

##### Re: Formatting Height
• 2011/1/22 1:49

• Friend of XOOPS

• Posts: 323

• Since: 2004/8/6 2

So if I used a select field
like
``` <select name="height">         <option selected="selected" value=""></option>         <option value="53">4'5"</option>         <option value="54">4'6"</option> </select> ```

and stored the VALUE in the database
Then on the template converted the VALUE to feet / inches

how do I write it

Sorry not a programmer but if you say the file name of a module and what woudl go in the file I should be able to figure it out.

Thanks this is the last piece to my puzzle

my database table is "height"
Arowana

##### Re: Formatting Height
• 2011/1/22 1:58

• Friend of XOOPS

• Posts: 323

• Since: 2004/8/6 2

When I did just the test field and put 5' 4" the database table filled with 0

Arowana

##### Re: Formatting Height
• 2011/1/22 2:04

• XOOPS is my life!

• Posts: 2335

• Since: 2004/11/20

Adding the single numeric value in inches to the DB via the select menu (as you have shown) and then getting the value back from the DB and doing the conversion to feet and inches in PHP (perhaps with the script posted by Mamba) is a better idea. It depends on the height range you want to use, otherwise you could have a very long select menu.
A thread is for life. Not just for Christmas.

### Recent Posts

• ##### Re: Login Block does not work
Yesterday 13:13 Bleekk
• ##### Re: Login Block does not work
7/1 11:03 heyula
• ##### Re: Login Block does not work
7/1 8:16 goffy
• ##### Login Block does not work
7/1 7:02 Bleekk
• ##### Re: Problems installing wgEvent 1.0.0 Alpha 1
6/25 16:19 Mamba
• ##### Re: Problems installing wgEvent 1.0.0 Alpha 1
6/25 6:10 goffy
• ##### Re: Problems installing wgEvent 1.0.0 Alpha 1
6/24 21:39 cronywell
• ##### Re: Problems installing wgEvent 1.0.0 Alpha 1
6/24 19:10 goffy
• ##### Re: Problems installing wgEvent 1.0.0 Alpha 1
6/24 16:31 cronywell
• ##### Re: If undefined function escapeshellcmd()
6/12 10:36 Mamba

### Who's Online

92 user(s) are online (50 user(s) are browsing Support Forums)

Members: 1

Guests: 91

### Donat-O-Meter

 Stats Goal: \$100.00 Due Date: Jul 31 Gross Amount: \$0.00 Net Balance: \$0.00 Left to go: \$100.00

### Latest GitHub Commits

• ##### {{ record.sha.slice(0, 7) }} - {{ record.commit.message | truncate }}
{{ record.commit.author.name }} {{ record.commit.author.date | formatDate }}