Results 1 to 6 of 6

Thread: better way to show grade in php

  1. #1
    Join Date
    Nov 2009
    Posts
    131

    better way to show grade in php

    Hello to all,
    I am new to this forum. I have written following program in php. Following program shows grades according to your percentage. I want to know, is there any better way to show grade in php? Please help me.
    I have written following code for your understanding.


    Code:
    if ( Grade >= 95 ) {
            echo "A";
        } elseif ( Grade >= 85 ) {
            echo "B";
        } elseif ( Grade >= 75 ) {
            echo "C";
        } else {
            echo "Fail."
        }

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: better way to show grade in php

    As per my knowledge you are using one of the simplest code to show grade according to percentage. It is one of the efficient and easy to understand code. In other code you have you have to use either switch case or you can use if else statement to show grade according to percentage. Just use this code in your program and run your program.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: better way to show grade in php

    Hey there is other way through which you can show grade of student according to his percentage. In other way you have to convert Grade into value so that it can be used in array. If you don't know how to do this then use following code.

    Code:
    Gradei = (int)Grade / 11;
    Graden= array('90' => 'A+', '80' => 'A', '70' => B, ..... );

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: better way to show grade in php

    As per my information the code you have written is very simple one but if you want more advanced and more fast execution then you can use following code. It is very simple program. In this program I have use switch statement.

    Gradei = (int)Grades / 10;
    case 10:
    case 9:
    Gradei = 'A';
    break;
    case 8:
    Gradei = 'B';
    break;
    case 7:
    Gradei = 'C';
    break;
    default:
    GradeName = 'Failed';
    }
    echo GradeName;

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: better way to show grade in php

    Hey there is no need to use switch statement or any other case. You can easily do this using simple if statement. I have written one simple code for you just try to understand it. It is very simple. In following code I have use one function called intGradeToStrGrade()


    Code:
    function intGradeToStrGrade(Grades) {
        if (Grades >= 95) return "A";
        if (Grades >= 85) return "B";
        ...
    }

  6. #6
    Join Date
    Jan 2012
    Posts
    1

    Re: better way to show grade in php

    Quote Originally Posted by Zecho View Post
    Hey there is no need to use switch statement or any other case. You can easily do this using simple if statement. I have written one simple code for you just try to understand it. It is very simple. In following code I have use one function called intGradeToStrGrade()


    Code:
    function intGradeToStrGrade(Grades) {
        if (Grades >= 95) return "A";
        if (Grades >= 85) return "B";
        ...
    }
    hello.. here is my form,
    <form id="form1" name="form1" method="post" action="">
    <label for="mark"></label>
    <label for="Submit"></label>
    <table width="421" height="150" border="0" align="center">
    <tr>
    <td width="112">Mark </td>
    <td width="9">:</td>
    <td width="278"><input type="text" name="mark" id="mark" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" id="Submit" value="Submit"/></td>
    </tr>
    </table>
    </form>



    how to call that function?

Similar Threads

  1. Preparation for SBI Clerk Grade Exams
    By Kash123 in forum Education Career and Job Discussions
    Replies: 10
    Last Post: 06-09-2012, 12:46 PM
  2. It is not worth to buy Consumer Grade Laptops
    By AkshatShetty in forum Portable Devices
    Replies: 7
    Last Post: 13-09-2011, 03:14 PM
  3. Need solid consumer-grade camera
    By Thenral in forum Portable Devices
    Replies: 5
    Last Post: 30-07-2011, 01:20 PM
  4. Best grade of aluminum sheet for CPU Tower
    By I'm Legend in forum Hardware Peripherals
    Replies: 5
    Last Post: 22-03-2011, 09:10 AM
  5. Calculate grade based on percentage
    By Adel123 in forum Software Development
    Replies: 2
    Last Post: 01-09-2009, 04:51 PM

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
  •  
Page generated in 1,711,631,187.20272 seconds with 17 queries