allpkresults Posted August 14, 2013 Share Posted August 14, 2013 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted August 14, 2013 Share Posted August 14, 2013 What? Quote Link to comment Share on other sites More sharing options...
Zane Posted August 14, 2013 Share Posted August 14, 2013 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 14, 2013 Share Posted August 14, 2013 if ( ($rollNumber >= 1 && $rollNumber <= 6702) || ($rollNumber >= 7101 && $rollNumber <= 7152) || ($rollNumber >= 20001 && $rollNumber <= 103090 ) ) $class = 9; else $class = 10; Take it from there. Quote Link to comment Share on other sites More sharing options...
allpkresults Posted August 16, 2013 Author Share Posted August 16, 2013 @Barand So where is % (Percentage) ??????? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 16, 2013 Share Posted August 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 16, 2013 Share Posted August 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
jcbones Posted August 16, 2013 Share Posted August 16, 2013 @Barand So where is % (Percentage) ??????? <?php function percentage($number,$total) { return round(($number / $total) * 100); } Quote Link to comment Share on other sites More sharing options...
allpkresults Posted August 20, 2013 Author Share Posted August 20, 2013 $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 numbernot gving me $percent variable value??? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2013 Share Posted August 20, 2013 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 | +-------+--------+---------+-------+------------+---------+ Quote Link to comment Share on other sites More sharing options...
allpkresults Posted August 22, 2013 Author Share Posted August 22, 2013 this is my sql ...but when i put following script for this sql its not working ....for every roll number script give $percent1 = ($mark_obtained / 1050) * 100; this result???????? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 22, 2013 Share Posted August 22, 2013 All those roll numbers are in class 10 so $percent1 is correct Quote Link to comment Share on other sites More sharing options...
allpkresults Posted August 22, 2013 Author Share Posted August 22, 2013 this is just top of my sql snap..in end all roll numbers available including 9th class Quote Link to comment Share on other sites More sharing options...
Barand Posted August 22, 2013 Share Posted August 22, 2013 Post your code. In the code you posted earlier roll is always 20000 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.