Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can someone help me with my PHP calculator?

    PHP Code:
    if($num%2==0){
    $html="<span style='color:purple;'>".$num.''</span>";
    /*divide by 2 without rest = even*/
    }
    else{
    $html="
    <span style='color:pink;'>".$num.''</span>";
    /*divide by 2 with rest 1 = odd*/

    Last edited by ShaneC; 11-13-2011 at 10:01 PM. Reason: Added PHP Code tags

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,455
    Thanks
    23
    Thanked 631 Times in 630 Posts
    If all you want is to set a variable then you will see nothing. If you want an output to look at :
    Code:
    <?php
    $num = 51;
    
    if($num%2 == 0)
    {
    	echo "<span style='color:purple;'>$num</span>";
    	/*divide by 2 without rest = even*/
    }
    else{
    	echo "<span style='color:black;'>$num</span>";
    	/*divide by 2 with rest 1 = odd*/
    }
    ?>
    You need to set the $num variable so the comparison is done.

    OR

    Code:
    <?php
    $num = 51;
    
    if($num%2 == 0)
    {
    	$html = "<span style='color:purple;'>$num</span>";
    	/*divide by 2 without rest = even*/
    }
    else{
    	$html = "<span style='color:black;'>$num</span>";
    	/*divide by 2 with rest 1 = odd*/
    }
    echo $html;
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •