brem13 Posted June 1, 2010 Share Posted June 1, 2010 trying to figure out how to calculate inches in php, or if that cant be done, how can i change my select statement to display inches in the drop down, but put the centemeter equivalent in the database, the calculation im talking about is something like > 4'6" & < 6'11' $array_height1 = array('Any', "4'1"", "4'2"", "4'3"", "4'4" etc); echo '<select name="height1">'; foreach($array_height1 as $aheight1) { $selected = (($aheight1 == $height1) ? ' selected="selected"' : ''); echo '<option value="'.$aheight1.'"'.$selected.'>'.$aheight1.'</option>'; }//end for would there be a way to do a >4'6" & < 6'11" sort of thing tho Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/ Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 mm i would say not but not sure either. The logical way would be to save inches in centimeters and call it that way 1 inch is 2.54 centimeters. I am pretty sure that 4'6" cannot be recognised as a number so do the math in centimeters. Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065970 Share on other sites More sharing options...
kenrbnsn Posted June 1, 2010 Share Posted June 1, 2010 This is basic math: 12 inches per foot. 2.54 centimeters per inch. So 5'6" is (5 * 12) + 6 and that converted into cm is ((5 * 12) + 6) * 2.54 It's not any different in PHP. Ken Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065972 Share on other sites More sharing options...
brem13 Posted June 1, 2010 Author Share Posted June 1, 2010 i figured as much. is there a way using the code i have to show inches on the page but store centimeters in the database? Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065973 Share on other sites More sharing options...
teamatomic Posted June 1, 2010 Share Posted June 1, 2010 Why dont you just convert it to inches? then you can compare and when you want to display just divide by 12 and use the modulus. $num=145; $ft=floor($num/12); $inch=$num%12; echo "$ft'$inch\"";//12'1" HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065980 Share on other sites More sharing options...
brem13 Posted June 1, 2010 Author Share Posted June 1, 2010 ok, ill try that, ty Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065981 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 set your array with keys as the value $array_height1 = array('0'=>'Any','124.46' => '4'1"'); foreach ($array_height1 as $array_height1value => $height) { echo '<option value="'.$array_height1value.'">'.$height.'</option>'; } Link to comment https://forums.phpfreaks.com/topic/203481-calculate-inches/#findComment-1065982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.