1. Home
  2. Computing & Technology
  3. PHP / MySQL

Convert Temperature

By , About.com Guide

3 of 4

Adding More Conversions

Still working in our convert.php file, add the following code at the end of the document, just before the ?> end PHP tag.

if ($scale == "fahrenheit")
{print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td>$degree</td><td>farhenheit</td></tr>";
$f_2_c = ($degree -32)*5/9;
print "<tr><td>$f_2_c</td><td>celsius</td></tr>";
$f_2_k = $f_2_c+273.15;
print "<tr><td>$f_2_k </td><td>kelvin</td></tr>";
$f_2_r = $degree+459.6;
print "<tr><td>$f_2_r</td><td>rankine</td></tr></table>";}

if ($scale == "kelvin")
{print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td>
$degree</td><td>kelvin</td></tr>";
$k_2_f = ($degree - 273.15) * 9 / 5 + 32;
print "<tr><td>$k_2_f</td><td>fahrenheit</td></tr>";
$k_2_c = $degree-273.15;
print "<tr><td>$k_2_c </td><td>celsius</td></tr>";
$k_2_r = $k_2_f+459.6;
print "<tr><td>$k_2_r</td><td>rankine</td></tr></table>";}

if ($scale == "rankine")
{print "<table border><tr><th colspan=2> Conversion Results</th></tr><tr><td>$degree</td><td>rankine</td></tr>";
$r_2_f = $degree-459.6;
print "<tr><td>$r_2_f</td><td>fahrenheit</td></tr>";
$r_2_c = ($r_2_f - 32)*5/9;
print "<tr><td>$r_2_c </td><td>celsius</td></tr>";
$r_2_k = $r_2_c + 273.15;
print "<tr><td>$r_2_k</td><td>kelvin</td></tr></table>";}
and put this code after the ?> closing PHP tag to close up our HTML

</body>
</html>
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Convert Temperature Formula - Convert Temperature - PHP Convert Temperature

©2009 About.com, a part of The New York Times Company.

All rights reserved.