Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a PHP Expert!

Join 244,308 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 810 people online right now. Registration is fast and FREE... Join Now!




PHP 'If selected' statements

 
Reply to this topicStart new topic

PHP 'If selected' statements

Linz
12 Nov, 2008 - 06:00 AM
Post #1

New D.I.C Head
*

Joined: 10 Nov, 2008
Posts: 9

What I am trying to make is a conversion site between the 5 units. When I display the site it shows 15 answers, rather than 5. So I believe I need some type of "if" this unit is "Selected" "then" display the 5 answers. Unfortunately since this is my first attempt at writing PHP I do not know how to write the statement.
here is my code:

CODE


<html>


  <head>
    <title> Lindsey's Conversion Help </title>
  </head>

  <body>

  <H3> Get ready to convert between Circumference, Radians, Degrees, Grade, and NauticalRhumb! </H2>


  <TABLE BORDER="2" CELLSPACING="0" CELLPADDING="3" style="background-color:#D0F18F;">
  <tr>
  <th>Please enter a number: </th>
  <th>Please select your units: </th>
  <th>Here is your Result!</th>
  </tr>
  <tr>
    <td>
        <form action="ConvertingUnits.php" method="POST" >
          Enter your number here! <br>
          <input type="text" name="number"/><br>
          <input type="submit" />  
        </form>
    </td>


    <td>
        <form name="myform" action="ConvertingUnits.php" method="POST">
        <div align="center">
        <select name="myselection">
        <option value="Circumference">Circumference</option>
        <option value="Radian">Radian</option>
        <option value="Degree">Degree</option>
        <option value="Grade">Grade</option>
        <option value="NauticalRhumb">NauticalRhumb</option>        
        </select>
        </div>
        </form>
    </td>

    <td>
                <?php

          $NauticalRhumb = $_POST["number"];
          if (is_numeric($NauticalRhumb))    {
              $Circumference = (($NauticalRhumb)*(0.03125));
              echo $Circumference ." Circumference <br>";
        }
        
          $NauticalRhumb = $_POST["number"];
          if (is_numeric($NauticalRhumb))    {
              $Degree = (($NauticalRhumb)*(11.25));
              echo $Degree ." Degree <br>";
        }
        
          $NauticalRhumb = $_POST["number"];
          if (is_numeric($NauticalRhumb))    {
              $Radian = (($NauticalRhumb)*(0.1963495));
              echo $Radian ." Radian <br>";
        }
        
          $NauticalRhumb = $_POST["number"];
          if (is_numeric($NauticalRhumb))    {
              $Grade = (($NauticalRhumb)*(12.5));
              echo $Grade ." Grade <br>";
        }




          $Grade = $_POST["number"];
          if (is_numeric($Grade))    {
              $Circumference = (($Grade)*(0.0025));
              echo $Circumference ." Circumference <br>";
        }
        
          $Grade = $_POST["number"];
          if (is_numeric($Grade))    {
              $Degree = (($Grade)*(0.9));
              echo $Degree ." Degree <br>";
        }
        
          $Grade = $_POST["number"];
          if (is_numeric($Grade))    {
              $Radian = (($Grade)*(0.01570796));
              echo $Radian ." Radian <br>";
        }
        
          $Grade = $_POST["number"];
          if (is_numeric($Grade))    {
              $NauticalRhumb = (($Grade)*(0.08));
              echo $NauticalRhumb ." NauticalRhumb <br>";
        }




          $Degree = $_POST["number"];
          if (is_numeric($Degree))    {
              $Circumference = (($Degree)*(0.002778));
              echo $Circumference ." Circumference <br>";
        }
        
          $Degree = $_POST["number"];
          if (is_numeric($Degree))    {
              $Grade = (($Degree)*(1.111));
              echo $Grade ." Grade <br>";
        }
        
          $Degree = $_POST["number"];
          if (is_numeric($Degree))    {
              $Radian = (($Degree)*(0.01745));
              echo $Radian ." Radian <br>";
        }
        
          $Degree = $_POST["number"];
          if (is_numeric($Degree))    {
              $NauticalRhumb = (($Degree)*(0.08889));
              echo $NauticalRhumb ." NauticalRhumb <br>";
        }




          $Radian = $_POST["number"];
          if (is_numeric($Radian))    {
              $Circumference = (($Radian)*(0.1591549));
              echo $Circumference ." Circumference <br>";
        }
        
          $Radian = $_POST["number"];
          if (is_numeric($Radian))    {
              $Grade = (($Radian)*(63.66198));
              echo $Grade ." Grade <br>";
        }
        
          $Radian = $_POST["number"];
          if (is_numeric($Radian))    {
              $Dergee = (($Radian)*(57.29578));
              echo $Degree ." Degree <br>";
        }
        
          $Radian = $_POST["number"];
          if (is_numeric($Radian))    {
              $NauticalRhumb = (($Radian)*(5.092958));
              echo $NauticalRhumb ." NauticalRhumb <br>";
        }




          $Circumference = $_POST["number"];
          if (is_numeric($Circumference))    {
              $Radian = (($Circumference)*(6.283));
              echo $Radian ." Radian <br>";
        }
        
          $Circumference = $_POST["number"];
          if (is_numeric($Circumference))    {
              $Grade = (($Circumference)*(400));
              echo $Grade ." Grade <br>";
        }
        
          $Circumference = $_POST["number"];
          if (is_numeric($Circumference))    {
              $Dergee = (($Circumference)*(360));
              echo $Degree ." Degree <br>";
        }
        
          $Circumference = $_POST["number"];
          if (is_numeric($Circumference))    {
              $NauticalRhumb = (($Circumference)*(32));
              echo $NauticalRhumb ." NauticalRhumb <br>";
        }



        else
          echo "Please enter a number!";
            
        ?>

    </td>
  </tr>
  </table>
  </body>
</html>





any help would be appreciated smile.gif

User is offlineProfile CardPM
+Quote Post


Hary
RE: PHP 'If Selected' Statements
12 Nov, 2008 - 06:38 AM
Post #2

D.I.C Regular
Group Icon

Joined: 23 Sep, 2008
Posts: 408



Thanked: 39 times
My Contributions
you can use the $_POST['myselection'] to switch:

CODE

          $NauticalRhumb = $_POST["number"];
          if ($_POST['myselection'] == "NauticalRhumb" && is_numeric($NauticalRhumb))    {
              $Circumference = (($NauticalRhumb)*(0.03125));
              echo $Circumference ." Circumference <br>";
        }


And you can reuse the $_POST['number'] var, you do'n need to read it for every conversion.

This post has been edited by Hary: 12 Nov, 2008 - 06:40 AM
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: PHP 'If Selected' Statements
12 Nov, 2008 - 06:51 AM
Post #3

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 1,571



Thanked: 94 times
Dream Kudos: 100
Expert In: PHP

My Contributions
You never test the results of "myform" to see if it's Circumference, Radian, etc.


User is online!Profile CardPM
+Quote Post

Linz
RE: PHP 'If Selected' Statements
13 Nov, 2008 - 12:42 PM
Post #4

New D.I.C Head
*

Joined: 10 Nov, 2008
Posts: 9

What do you mean?
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: PHP 'If Selected' Statements
13 Nov, 2008 - 04:25 PM
Post #5

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 1,571



Thanked: 94 times
Dream Kudos: 100
Expert In: PHP

My Contributions
You set each of these variables: $NauticalRhumb, $Grade, $Degree, $Radian, and $Circumference to be $_POST['number'] and then if they are a number (which they will be if $_POST['number'] is one!) you calculate and echo 4 values based on each of them. That means that you should expect twenty calculations (4X5) to be done whenever $_POST['number'] a number!
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 06:59PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month