newbie question, almost there.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edster
Forum Newbie
Posts: 1
Joined: Thu Nov 12, 2009 6:34 pm

newbie question, almost there.

Post by edster »

Hi all, Im new to ph and this forum! I'm taking a beginners class in PHP and I'm having trouble a bit of trouble. Below is my code. I finally got the actually temp conversion to work properly, however I wanted it to be displayed in a table. One column for Celsius and for the featherweight equivalent. (or the opposite way, you get the point)

I have tried outputting to the table, with no luck tho I do think I am on the right track. Any suggestions or guidance? Thanks

Code: Select all

 
<?php
 
$ctemp = -40;
print "<table>"; 
while ($ctemp <= 200) {
 
        print (<tr><td>$ctemp . " &deg;"</td>);
        print (32 + $ctemp / 5 * 9  );
        print (<td>" &deg;<br/>"<br></td></tr>);
        $ctemp = $ctemp + 10;
        
}
print "</table>"; 
?>
jackbutler1
Forum Newbie
Posts: 3
Joined: Thu Nov 12, 2009 4:21 pm

Re: newbie question, almost there.

Post by jackbutler1 »

Just a couple of little errors; you are trying to print the farenheit temperature inbetween two cells. If you look below you will see that I have done the calculation and stored it in a variable called $ftemp, then inserted this variable inside the next cell. Also, you had not enclosed your <tr>s and <td>s in quotation marks. Anything thats not a php function or variable must be enclosed in quotation marks. I have also removed the <br/> because i couldnt see why they were there?
Heres the edited code:

Code: Select all

 
<?php
 
$ctemp = -40;
print "<table>"; 
while ($ctemp <= 200) {
 
        print ("<tr><td>$ctemp &deg;</td>");
        $ftemp=$ctemp/5*9+32;
        print ("<td>$ftemp&deg;</td></tr>");
        $ctemp = $ctemp + 10;
        
}
print "</table>"; 
?>
If you have any questions i will be happy to answer them :)
Post Reply