Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 42

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

  1. #11
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    Do not use single quotes for numbers

    $a = 3;
    $b = 8;



    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/numbers.php

    Code:
    <?php
    // Number comparison
      $a='3';
      $b='8';
     if ($a<$b)
     {
     echo $a. 'is smaller than'.$b;
     }

  2. #12
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I got an error

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

    Code:
    Parse error:  syntax error, unexpected 'if' (T_IF) in /home/fwhphp/public_html/sherly/medicine.php on line 3
    Code:
    <?php
    $overtime=40
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount : $pay_amount : Medicine : $medicine';
    }
    else
    {
    $$pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount : $pay_amount : Medicine : $medicine';
    }

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

    Default

    $overtime=40
    Missing ending semicolon (;)
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  4. #14
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    http://php.flashwebhost.com/annie/if...reater_bug.php

    Code:
    <?php
    $passScore = 210;
    $studentName = 'Mike';
    $studentScore = 190;
    if ($studentScore > $passScore) {
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    } else {
    
    echo 'Passing Score is'  .  $passScore . '.Your Score is' . $studentScore ; 
    
    echo '<br>';
    
    echo 'Sorry You did not pass the exam. Good luck and Cheers next time. ';
    }

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

    Default

    Quote Originally Posted by annie View Post
    http://php.flashwebhost.com/annie/if...reater_bug.php

    Code:
    <?php
    $passScore = 210;
    $studentName = 'Mike';
    $studentScore = 190;
    if ($studentScore > $passScore) {
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    } else {
    
    echo 'Passing Score is'  .  $passScore . '.Your Score is' . $studentScore ; 
    
    echo '<br>';
    
    echo 'Sorry You did not pass the exam. Good luck and Cheers next time. ';
    }
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    On this line, you have $studentMark, this variable is not defined (created/used) in that program.. It should be replaced with $studentScore.

    Use tab for indent code inside { and }, refer my code. Code inside { and } is called code block, must be indented (press TAB key).
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #16
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    Try this code

    Code:
    <?php
    $overtime=40;
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount ' . $pay_amount .' Medicine ' . $medicine;
    }
    else
    {
    $pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount ' . $pay_amount . ' Medicine ' . $medicine;
    }

    Quote Originally Posted by sherlyk View Post
    I got an error

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

    Code:
    Parse error:  syntax error, unexpected 'if' (T_IF) in /home/fwhphp/public_html/sherly/medicine.php on line 3
    Code:
    <?php
    $overtime=40
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount : $pay_amount : Medicine : $medicine';
    }
    else
    {
    $$pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount : $pay_amount : Medicine : $medicine';
    }

  7. #17
    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

  8. #18
    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

  9. #19
    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. #20
    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.

Page 2 of 5 FirstFirst 1234 ... 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
  •