Page 1 of 2 12 LastLast
Results 1 to 10 of 42

Thread: Day 4 - Decision Making - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default

    http://php.flashwebhost.com/melbin/days.php

    PHP Code:
    <?php
    $day
    ='Sunday';
    if (
    $day="Sunday") {
        echo 
    'Have a nice Sunday';
    }

    else {
        echo 
    'Have a nice day';
    }
    In this code when i use == on line no:3
    if ($day=="Sunday") {
    i am getting the result as FALSE. Why ?

    Doubt 2

    Is it possible to get the day by using PHP date and time function ?
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  2. #2
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default

    http://php.flashwebhost.com/melbin/result.php

    PHP Code:
    <?php
    $mark
    =85// Enter Mark between 1 and 100

    if ($mark 100){
        echo 
    "$mark/100 ???... INVALID MARK";
    }

    else if (
    $mark >= 80 and $mark <= 100){
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : Distinction';
    }

    else if (
    $mark >=60 and $mark <80) {
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : First Class';
    }

    else if (
    $mark >=50 and $mark <60) {
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : Second Class';
    }

    else if (
    $mark >=and $mark <50) {
        echo 
    'Sorry You did not pass the exam. Your Mark is ' $mark ' - Status : FAILED';
    }

    else {
        echo 
    'INVALID MARK';
    }
    Last edited by melbin; 05-13-2014 at 03:39 AM. Reason: script url missed
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  3. #3
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by melbin View Post
    http://php.flashwebhost.com/melbin/result.php

    PHP Code:
    <?php
    $mark
    =85// Enter Mark between 1 and 100

    if ($mark 100){
        echo 
    "$mark/100 ???... INVALID MARK";
    }

    else if (
    $mark >= 80 and $mark <= 100){
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : Distinction';
    }

    else if (
    $mark >=60 and $mark <80) {
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : First Class';
    }

    else if (
    $mark >=50 and $mark <60) {
        echo 
    'Congratulations You have got ' $mark ' Marks - Grade : Second Class';
    }

    else if (
    $mark >=and $mark <50) {
        echo 
    'Sorry You did not pass the exam. Your Mark is ' $mark ' - Status : FAILED';
    }

    else {
        echo 
    'INVALID MARK';
    }
    Good script.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  4. #4
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/discount.php

    Code:
    <?php 
     $over65=true; 
     $price = 3.00; 
     if ($over65) 
     { 
     $discount =.90; 
    echo  "You have received our senior's discount, your price is $" . $price*$discount; 
     } 
     else 
     { 
    echo "Sorry you do not qualify for a discount, your price is $" . $price; 
     } 
     ?>
    Last edited by sherlyk; 05-13-2014 at 07:30 AM.

  5. #5
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/fish_can_fly.php

    Code:
    <?php
    $fishsCanFly = 'yes';
    if ($fishsCanFly == 'yes') {
    echo 'then we can never have a fish curry' ;
     }
    if ( $fishsCanFly == 'no') {
    echo 'then we can have as much fish as we want' ;
     }

  6. #6
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/fish_can_fly.php

    Code:
    <?php
    $fishsCanFly = 'yes';
    if ($fishsCanFly == 'yes') {
    echo 'then we can never have a fish curry' ;
     }
    if ( $fishsCanFly == 'no') {
    echo 'then we can have as much fish as we want' ;
     }
    Nice program, fishes love water.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  7. #7
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/if_greater.php

    Code:
    <?php
    $totalScoreRequiredToUnlockTheNextLevel = 8000;
    $playerName = 'stefin';
    $yourScore = 16000;
    if ($yourScore > $totalScoreRequiredToUnlockTheNextLevel) {
    echo 'Congratulations ' . $playerName . ' ! hurrah You Have Cleared The Level your score is' .  $yourScore . ' point' 
    ;  
    }

  8. #8
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/if_greater.php

    Code:
    <?php
    $totalScoreRequiredToUnlockTheNextLevel = 8000;
    $playerName = 'stefin';
    $yourScore = 16000;
    if ($yourScore > $totalScoreRequiredToUnlockTheNextLevel) {
    echo 'Congratulations ' . $playerName . ' ! hurrah You Have Cleared The Level your score is' .  $yourScore . ' point' 
    ;  
    }

    You win, dragon eggs are on the way
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  9. #9
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by melbin View Post
    http://php.flashwebhost.com/melbin/days.php

    PHP Code:
    <?php
    $day
    ='Sunday';
    if (
    $day="Sunday") {
        echo 
    'Have a nice Sunday';
    }

    else {
        echo 
    'Have a nice day';
    }
    In this code when i use == on line no:3 i am getting the result as FALSE. Why ?
    = is assignment operator, that means you are just assigning a value to variable $day.

    Use == operator to check if value is same or not.


    Quote Originally Posted by melbin View Post
    Doubt 2

    Is it possible to get the day by using PHP date and time function ?
    It is possible using date() function.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  10. #10
    Join Date
    May 2014
    Posts
    21

    Lightbulb = and ==

    Quote Originally Posted by melbin View Post
    http://php.flashwebhost.com/melbin/days.php

    PHP Code:
    <?php
    $day
    ='Sunday';
    if (
    $day="Sunday") {
        echo 
    'Have a nice Sunday';
    }

    else {
        echo 
    'Have a nice day';
    }
    In this code when i use == on line no:3 i am getting the result as FALSE. Why ?

    Doubt 2

    Is it possible to get the day by using PHP date and time function ?
    i used ur code and found no error even when i used == in line 3.

    and
    Code:
    if ($day="Sunday")
    is a wrong code. bez in this you are give $day the value "Sunday",and in this case the if-statement will be always executed.

    check as
    Code:
    if($day = 'monday')
    in this code too the if statement will be execute bez all you doing is telling the compiler that the value of $day variable is now 'monday' and not to check if $day is equal to 'monday'.

    x == y;
    tells the compiler to check if left hand side (x) of [ == ] is equal to the right hand side (y).

    x=y;
    tells the compiler that now the value of y is to given to x also.

    i think the point is clear..

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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