swizenfeld Posted December 22, 2009 Share Posted December 22, 2009 Hello i just started working with php and i am kind of stuck here i want to be able to enter a number in an xhtml page and then select from a drop down menu Celsius, Kelvin, or Fahrenheit. (which i already created) and then get the convertion. result should be : example: Enter number : 1 Select from drop menu : Celsius Celsius = 1 Kelvin = xxx Fahrenheit = xxx if need a better visual you can see a perfect example here http://cim.saddleback.edu/~skinoshita1/cim225/h10input.html Link to comment https://forums.phpfreaks.com/topic/185996-new-to-php-temp-convertion/ Share on other sites More sharing options...
cags Posted December 22, 2009 Share Posted December 22, 2009 So what's your question? If the question is how to convert one to the other it seems a bit out of the scope of the forum and can easily found with a 2 second Google search. Or is your question about how to proceed programatically? If your after something similar to the link you provided it's a simple switch statement or an if/elseif nest to calculate. if($_GET['type'] == 'Celsius') { $Kelvin = $_GET['temp'] - 273.15; $Fahrenheit = 'whatever the formula is'; $Celsius = $_GET['temp']; } elseif($_GET['type'] == 'Kelvin') { $Kelvin = $_GET['temp']; $Fahrenheit = 'whatever'; $Celsius = $_GET['temp'] + 273.15; } elseif($_GET['type'] == 'Fahrenheit') { $Kelvin = 'whatever'; $Fahrenheit = 'whatever'; $Celsius = 'whatever'; } else { die("Error"); } echo 'Kelvin = ' . $Kelvin . '<br/>'; echo 'Fahrenheit = ' . $Fahrenheit . '<br/>'; echo 'Celsius' = ' . $Celsius . '<br/>'; I'm not sure on the exact formula for converting Fahrenheit, but I'm sure it can be found in about 5 seconds flat. Link to comment https://forums.phpfreaks.com/topic/185996-new-to-php-temp-convertion/#findComment-982173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.