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

  • Arowana

  • 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

2
Peekay
Re: Formatting Height
  • 2011/1/22 1:00

  • Peekay

  • 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.

3
Arowana
Re: Formatting Height
  • 2011/1/22 1:06

  • Arowana

  • 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

4
Mamba
Re: Formatting Height
  • 2011/1/22 1:11

  • Mamba

  • Moderator

  • Posts: 11366

  • 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($feet2);

  
// 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

5
Peekay
Re: Formatting Height
  • 2011/1/22 1:22

  • Peekay

  • 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.

6
Mamba
Re: Formatting Height
  • 2011/1/22 1:31

  • Mamba

  • Moderator

  • Posts: 11366

  • 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

7
Peekay
Re: Formatting Height
  • 2011/1/22 1:35

  • Peekay

  • 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.

8
Arowana
Re: Formatting Height
  • 2011/1/22 1:49

  • Arowana

  • 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

9
Arowana
Re: Formatting Height
  • 2011/1/22 1:58

  • Arowana

  • 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

10
Peekay
Re: Formatting Height
  • 2011/1/22 2:04

  • Peekay

  • 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.

Login

Who's Online

222 user(s) are online (117 user(s) are browsing Support Forums)


Members: 0


Guests: 222


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits