Jump to content

Multiple do Whiles in PHP ?!??!


pereira2k5

Recommended Posts

Hello I am a new user and a noob when it comes to PHP coding, people this is the thread to get ur laugh of the day. My question is how do I created two do-while php loops in the same webpage. The basic code is converting Celsius to Fahrenheit and vice-versa. When I get the results I get the same loop going rather than two different ones. So when The second part comes up with Converting Celcius to Fahrenheit, the celcius starts at 103.9 instead of 0 and loops for a while. can anyone help me? Thanks alot

<!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=ISO-8859-1" />
<title>Fahrenheit</title>
<style type="text/css">
<!--
#Layer1 {
   position:absolute;
   width:356px;
   height:53px;
   z-index:1;
   left: 0px;
   top: 0px;
}
#Layer2 {
   position:absolute;
   width:356px;
   height:54;
   z-index:2;
   left: 362px;
   top: 0px;
}
.style3 {font-size: 24px}
-->
</style>
</head>

<body>

<div id="Layer1">
  <table width="359" border="1" id="F2C">
    <tr>
      <td width="406"><h1 class="style3"> Converting Fahrenheit to Celcius </h1></td>
    </tr>
    <tr>
      <td><?php

do
{

   
      $fahrenheit++;

      $celsius = (($fahrenheit - 32)*.55);
      echo " $celsius degree(s) celcius";
      echo " <p> $fahrenheit degree(s) farhrenheit =";
      

} while ($fahrenheit<=100); 





?></td>
    </tr>
  </table>
</div>


<div id="Layer2">
  <table width="355" border="1">
    <tr>
      <td><h1 class="style3"> Converting Celcius to Fahrenheit </h1></td>
    </tr>
    <tr>
      <td><?php

do
{

   
      $celsius++;

      $fahrenheit = ($celsius*1.+32;
      echo "   $fahrenheit degree(s) farhrenheit";
      echo "<p>$celsius degree(s) celcius =";

      

} while ($celsius<=100); 





?>
</td>
    </tr>
  </table>
</div>

</body>
</html>

 

Link to comment
Share on other sites

I would use "for" loops instead of "do" loops in these cases:

<?php
for ($f=0;$f<101;$f++) {
   $c = (($f - 32)*.55);
   echo $c . ' degrees Celsius is ' . $f . ' degrees Fahrenheit<br>';
}?>

and

<?php
for ($c=0;$c<101;$c++) {
   $f = ($c*1.+32;
   echo $f . ' degrees Fahrenheit is ' . $c . ' degrees Celsius<br>';
}?>

 

Ken

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.