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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Solution teamatomic Posted June 1, 2010 Solution 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 Quote Link to comment Share on other sites More sharing options...
brem13 Posted June 1, 2010 Author Share Posted June 1, 2010 ok, ill try that, ty Quote Link to comment 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>'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.