Page 1 of 1

newbie question, almost there.

Posted: Thu Nov 12, 2009 6:38 pm
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>"; 
?>

Re: newbie question, almost there.

Posted: Thu Nov 12, 2009 7:03 pm
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 :)