11
Arowana
Re: Formatting Height
  • 2011/1/22 2:56

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


That is exactly what I want to do I just do not know how to do it.

I tried adding the function from mamba to my common.inc.php file but I got a blank white page
Arowana

12
redheadedrod
Re: Formatting Height

As I see it there are a couple different ways to do this.

You can offer a way for the individual to enter the feet and inches then from there you can convert it to total inches and save in the database. Then you can convert it back when you read it from the database into the format you want.

And for this you could have a select box for feet and one for inches. Then you look at what was returned. (Remember that select boxes start at 0 as the first option.)

Or you can have to entry boxes for someone to enter the numbers in directly.

Select boxes do not require any "validation" but you do have to set up an array with the options available.


You could do it with radio buttons with each available height as well. And store the chosen selection.


You can also do a long select list with all of the selections in it and save the number returned to the database. This is a simple solution but you have to have an array setup with all the possible selections.

Anytime you use select boxes it will require an array of options to choose from. This same array is used as selections to choose the option as well as to display the chosen option.

I sent you code based on select boxes and you could just copy the code directly from that. It is a simple solution and is easy to implement. However the "prefered" method would be to get the total inches and store those since then you have a real number to work with instead of an array index.

Rodney

13
Arowana
Re: Formatting Height
  • 2011/1/22 3:23

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


red,

I have got the select list and the value that goes into the database is in inches. So that is done No problem there.

Now to convert it back when you read it from the database is what I am after. Right now it reads in inches because that is what is in the database.

I tried using the convert code from mamba and it created a blank white page.

Anyone else got a snip of code for this process? my database table is named height

and

What code would be needed in the template / Display page to make this work?
Arowana

14
redheadedrod
Re: Formatting Height

Ok if you have the total inches....

And you have them in a variable called $height....


For your template you could have two more variables..

$height_feet and $height_inches

This code SHOULD work to get them....
Do this to your variables BEFORE sending them to the template.

$height_inches = $height % 12
$height_feet = ($height - $height_inches) / 12

Then if you set these two up for your template like you do for the other variables...

Then in your template you would just call each as the different variable that it is...

With something like <{height_feet}>'<{height_inches}>"

Actual code would be the variables you use and realize this is HTML code in the template and not PHP.

As to the two lines of math... I havent actually typed them in and tried them but the intention is...

First line will return the remanding number after dividing by 12.. Or the "inches"...

Second line will first subtract the extra inches off the height making it a dividable by 12 number then dividing by 12 to obtain the feet.

15
Arowana
Re: Formatting Height
  • 2011/1/22 7:02

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


can this be put into common.inc.php as a function?
$height_inches $height 12
$height_feet 
= ($height $height_inches) / 12

If Yes, how would you right the function

xRoster = sql table
height = sql row

function getHeight{
$height_inches $height 12;
$height_feet = ($height $height_inches) / 12;
}
Arowana

16
Arowana
Re: Formatting Height
  • 2011/1/22 20:35

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


Anyone have some ideas?

Sorry pretty stuck here
Arowana

17
Arowana
Re: Formatting Height
  • 2011/1/22 22:23

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


What is wrong with this function? Willing to hirer someone at this point, anyone got a few minutes that can program this function?

function getHeight($height){
    global 
$xoopsDB;
    
$query 'SELECT height FROM ' $xoopsDB->prefix('xRoster') . ' WHERE id =id';
    
$inches $height 12;
    
$feet = ($height $height_inches) / 12
}
Arowana

18
Arowana
Re: Formatting Height
  • 2011/1/22 23:45

  • Arowana

  • Friend of XOOPS

  • Posts: 323

  • Since: 2004/8/6 2


EDIT Removed post testing failed
Arowana

19
redheadedrod
Re: Formatting Height

That function is not even close to what would work..

You would have been passing the height to the function which means you dont need the query...

And you have to return a variable and you can only do one so you would have to convert it to a string and return the string.

The way we worked it out over yahoo should work ok for you.

If you would have done something like...

function getheight($height) {
  
$inches $height 12;
  
$feet = ($height $inches) / 12;
  return 
$feet " ' " $inches ' " ';
}


This MIGHT have worked. Haven't tried something like this with a function yet though.

Then you would have called it like...

$finalheight=getheight($height);


Rodney

Login

Who's Online

70 user(s) are online (40 user(s) are browsing Support Forums)


Members: 0


Guests: 70


more...

Donat-O-Meter

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

Latest GitHub Commits