...

View Full Version : PHP converting units code (advise)



jnt
05-22-2011, 10:21 AM
Hi, i am new in php and i want to make php page for converting units (lenght, time, weight etc.).

But before i start, i wanted to ask: is it smart to do this in php (js or something else)? And how did i started, what do you think about this code below?

Here is my idea:





<?php

$vre = $_POST['vrednost'];
$jed = $_POST['jed'];
$ujed = $_POST['ujed'];

if ($jed == "celsius")

switch ($ujed){
case "celsius":
echo "Same thing.";
break;
case "farenheit":
echo (number_format(($vre*(9/5)+32),2));
break;
case "kelvin":
echo (number_format(($vre + 273.15),2));
break;
}

elseif ($jed == "farenheit")

switch ($ujed){
case "celsius":
echo (number_format((($vre-32)*(5/9)),3));
break;
case "farenheit":
echo "Same thing.";
break;
case "kelvin":
echo (number_format((($vre+459.67)*(5/9)),3));
break;
}

elseif ($jed == "kelvin")

switch ($ujed){
case "celsius":
echo (number_format(($vre-273.15),2));
break;
case "farenheit":
echo (number_format(($vre * (9/5) - 459.67),2));
break;
case "kelvin":
echo "Same thing.";
break;
}

mlseim
05-22-2011, 04:02 PM
I would use javascripting only because the conversion would be immediate,
without a page refresh. You could also use AJAX, combination of PHP and
javascripting. A good way to learn some programming.

I would probably pick a better topic than the conversion thing. But perhaps
this is a homework assignment (for a class)?


.

jnt
05-23-2011, 01:06 PM
No, it's not homework , i finished school long time ago :) I just wanted to practice PHP through this.Well, maybe i choose bad example.Do you have some advice what to make? :D

Btw, i had same idea, to use AJAX, but i'm new in js too :D

And one more question: is this code i wrote too complicated (can it be more simpler)?

p.s. sry for bad english :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum