PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Dec 19, 2014 10:42 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Apr 23, 2011 5:20 pm 
Offline
Forum Newbie

Joined: Sat Apr 23, 2011 5:02 pm
Posts: 2
Hi everyone,
I am new at writing in php, first and foremost.
I am attempting to display a list of 0-100 degrees Fahrenheit, with its equivalent value in Celsius. I made these little functions to convert the temps, but I'm stumped on how to show them side by side (or one under the other) in a list on the page. If anyone knows a good way to do this, I would be much obliged.
Syntax: [ Download ] [ Hide ]
<?php
        function tempCtoF($c)
        {
                $f = $c * (9.0/5.0) + 32;
                return $f;
        }
        function tempFtoC($f)
        {
                $c = $f * (5.0/9.0) - 32;
                return $c;
        }
?>
 


Top
 Profile  
 
PostPosted: Sat Apr 23, 2011 6:54 pm 
Offline
Jack of Zircons
User avatar

Joined: Thu Nov 09, 2006 9:30 pm
Posts: 4484
Location: California, USA
Probably the easiest way would be to create an HTML table. Increment the cell in the left column by one for each row. Something like this:
Syntax: [ Download ] [ Hide ]
<?php
echo "<table>";
for($n=0; $n <= 100; $n++) {
   echo "tr><td>$n</td><td>".tempFtoC($n)."</td></tr>";
}
echo "</table>";

But I don't think your conversion algorithms are correct. Try substituting a couple of trial numbers (say, for freezing) and you will see what I mean. And you only need one of them, unless you are going to create 2 tables.


Top
 Profile  
 
PostPosted: Sat Apr 23, 2011 9:09 pm 
Offline
Forum Newbie

Joined: Sat Apr 23, 2011 5:02 pm
Posts: 2
Thank you so much Califdon, works excellently. Thank you also for the pointer on my conversion algorithms, I see the light now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group