Page 1 of 1
Just a beginner
Posted: Sun May 31, 2009 1:19 pm
by jamesbirdsley
I am just starting and i am trying to run a simple loop... for some reason it is not working... any one have any advice?
here is the code.. thanks
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
print '<table>';
print '<tr><th>Farenheit</th><th>Celsius</th></tr>';
for ($far=-50; $far <=50; $far +=5;{
$celsius= ($far -32)*5/9;
print "<tr><td>$far</td><td>$celsuis</td></tr>";
}
print '</table>';
?>
</body>
</html>
Re: Just a beginner
Posted: Sun May 31, 2009 1:30 pm
by kcormier
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
print '<table>';
print '<tr><th>Farenheit</th><th>Celsius</th></tr>';
// look below: you were missing ) which I've added & bolded for readability
for ($far=-50; $far <=50; $far +=5[b])[/b]{
// read note below for following line.
$celsius= ($far -32)*5/9;
print "<tr><td>$far</td><td>$celsuis</td></tr>";
}
print '</table>';
?>
</body>
</html>
I don't know if you're only going to be working in php and that's it or if you plan on going further and learning other languages. In php 5/9 will evaluate correctly, but a lot of languages will see that 5 is an integer and 9 is an integer and as such return the answer rounded to an int (in this case 0). So while it works correctly in php it's a pitfall to be careful of if you ever move over to other languages. If you plan on branching out of php ever I suggest getting into the convention of writing all floating point numbers (numbers with decimal places) with the decimal point. So I'd write that as:
Re: Just a beginner
Posted: Sun May 31, 2009 2:15 pm
by jamesbirdsley
thanks i appreciate the help...
for some reason it still is not working... i feel like im missing something..
i just save this as a .php and then open it with firefox, and i have wamp running... for somereason the output from firefox is :
'; print 'FarenheitCelsius'; for ($far=-50; $far <=50; $far +=5;){ $celsius= ($far -32)*5/9; print "$far$celsuis"; } print ''; ?>
Re: Just a beginner
Posted: Sun May 31, 2009 3:04 pm
by mikemike
Are you sure WAMP is running correctly and in that directory?
Also, I assume you noted the missing bracket ')' at the end of line 15 - that might be causing your issue.
Re: Just a beginner
Posted: Sun May 31, 2009 4:30 pm
by jamesbirdsley
got it... thanks for the help