Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    11
    Member #
    1962
    I'm trying to do this activity from my Sam's TY PHP in 24 Hours book, but I can't figure this out.

    The instructions say to create two variables and assign a value to each, then to test that the first variable is the same as, less than, greater than, or less than or equal to the second, and to print the result of each to the browser. I can't find out how to print the result to the browser... here's the code

    PHP Code:
    <?php
            $a4 
    "4"
            
    $b2 "2";
            print ( 
    $a4 $b2 );
            print ( 
    $a4 $b2 );
            print ( 
    $a4 $b2 );
            print ( 
    $a4 <= $b2 );
        
    ?>
    and the result - http://www.macfixation.com/phpTests/activity.php

    what am i doing wrong here?

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    First, you're comparing strings instead of numbers. Second, try something similar to the following because echoing false doesn't actually do anything:
    PHP Code:
    function pretty_boolean($value)
    {
        return (
    $value "true" "false");
    }

    $a4 4;
    $b2 2;

    echo 
    pretty_boolean($a4 == $b2);
    echo 
    pretty_boolean($a4 $b2);
    .
    .

    Also note the == instead of =. By doing =, you're assigning $b2 to $a4 (which always returns true). == is the comparison operator.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Member nepharo's Avatar
    Join Date
    Jun 2003
    Posts
    73
    Member #
    1729
    you could also try:

    PHP Code:
    <?
            $a 
    "4"
            
    $b "2";

    if( 
    $a == $b )
    echo 
    " a is equal to b" ;

    else if ( 
    $a $b )
    echo 
    " a is less than b";

    else if( 
    $a $b )
    echo 
    " a is greater than b";


        
    ?>
    in the previous statements, if a is equal to b, the first echo statement is printed and the other else if statements are skipped, which is what you want since if they are both equal there would be no need for testing for the other possibilities. Notice, like Filb said, that we are testing for equallity, thus we use == instead of = . The = is the assigment operator. This means that $a = $b is saying "assign the contents of $b to $a. Try changing the values of a and b at the beginning to get to the other results. Remember, use echo, print, and printf to show stuff on the browser. Go to www.php.net and download the manual. Is really helpful.
    I cannot self terminate, you must lower me into the fire.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com