Jump to content

Recommended Posts

i have examination result script now i am in trouble plz solve my problem "i have one database and full examination result 9th & 10th Class so 9th total marks 525 and 10th total marks 1050, now when i want to get % of 9th class its divide with 525 and when i want to get 10th class i must divide it to 1050, 9th class roll number start from 1 to 6702 and 7101 to 7152 and 20001 to 103090 rest of roll number are 10th class roll number " So plz tell me how can i make the if condition logic to get accurate % of my result or any other option or solution plz tell me regards

if ( ($rollNumber >= 1 && $rollNumber <= 6702) || ($rollNumber >= 7101 && $rollNumber <= 7152) || ($rollNumber >= 20001 && $rollNumber <= 103090 ) )
    $class = 9;
else
    $class = 10;

Take it from there.

Were you going for a time record when you wrote this question?  I suggest you devote more time than just 30 seconds to describing your problem.  Effective questions yield effective answers.

 

Give us more and we can give you more

well i think the the reason why you dont understand the answers is because no one understands your question. post the code that you have now and try to explain on it as to what the problem is and the idea you have to solving it and where you are stack then we shall start from there

$roll = 20000;
      $mark_obtained = $Row['Marks'];
      $percent = ($mark_obtained / 525) * 100;

    


      $percent1 = ($mark_obtained / 1050) * 100;
      
if(
($roll >= 1 && $roll <= 6702) ||
($roll >= 7101 && $roll <= 7152) ||
($roll >= 20001 && $roll <= 103090)
){
print $percent;
}else{
print $percent1;
};

i made this scripts but its not working properly, this script getting $percent1 variable value in every roll number
not gving me $percent variable value???

I got a different percentages when using roll numbers 20000 and 20001 ???

 

I'd create a table with those roll ranges and use that in the queries to find the class. For example

$sql = "CREATE TABLE studentclass (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    class INT,
    rollfrom INT,
    rollto INT
)";


$sql = "INSERT INTO studentclass (class, rollfrom, rollto) VALUES
(9, 1, 6702),
(10, 6703, 7100),
(9, 7101, 7152),
(10, 7153, 20000),
(9, 20001, 103090),
(10, 103091, 999999)
";

Then calculate the class totals and get the percentages with

SELECT c.class, s.roll, s.name, s.marks, totals.classtotal,
            (s.marks/totals.classtotal)*100 as pcent
        FROM student s
            INNER JOIN studentclass c ON s.roll BETWEEN c.rollfrom AND c.rollto
        INNER JOIN
            (
            SELECT c.class, SUM(s.marks) as classtotal
            FROM student s
                INNER JOIN studentclass c ON s.roll BETWEEN c.rollfrom AND c.rollto
            GROUP BY c.class
            ) totals USING (class)
        ORDER BY class, roll

With my test data

+--------+---------+-------+
| roll   | name    | marks |
+--------+---------+-------+
|    300 | John    |    50 |
|    500 | Jayne   |    62 |
|   6705 | Mary    |    70 |
|   6706 | Fred    |    65 |
|   6708 | David   |    50 |
|   7101 | Emma    |    52 |
|   7102 | Eric    |    45 |
|   7151 | Harry   |    68 |
|   7152 | Diana   |    82 |
|   7153 | Eileen  |    66 |
|  20000 | Jean    |    77 |
|  20001 | Mark    |    61 |
| 103090 | Martin  |    59 |
| 103091 | Anthony |    70 |
+--------+---------+-------+

this gave

+-------+--------+---------+-------+------------+---------+
| class | roll   | name    | marks | classtotal | pcent   |
+-------+--------+---------+-------+------------+---------+
|     9 |    300 | John    |    50 |        479 | 10.4384 |
|     9 |    500 | Jayne   |    62 |        479 | 12.9436 |
|     9 |   7101 | Emma    |    52 |        479 | 10.8559 |
|     9 |   7102 | Eric    |    45 |        479 |  9.3946 |
|     9 |   7151 | Harry   |    68 |        479 | 14.1962 |
|     9 |   7152 | Diana   |    82 |        479 | 17.1190 |
|     9 |  20001 | Mark    |    61 |        479 | 12.7349 |
|     9 | 103090 | Martin  |    59 |        479 | 12.3173 |
|    10 |   6705 | Mary    |    70 |        398 | 17.5879 |
|    10 |   6706 | Fred    |    65 |        398 | 16.3317 |
|    10 |   6708 | David   |    50 |        398 | 12.5628 |
|    10 |   7153 | Eileen  |    66 |        398 | 16.5829 |
|    10 |  20000 | Jean    |    77 |        398 | 19.3467 |
|    10 | 103091 | Anthony |    70 |        398 | 17.5879 |
+-------+--------+---------+-------+------------+---------+
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.