Page 1 of 1

a question / urgent

Posted: Sun May 10, 2009 11:04 pm
by kevin_zer0

hello everybody , i have a question , i have a field named 'average' in my mySql db that contains averages of 200 students , now i want to know how can i assign a grade to each students according to his average ? for example the most high avg gets the grade '1' , next '2' and so on , plz help m :banghead:


thanks in advance :roll:

Re: a question / urgent

Posted: Mon May 11, 2009 12:03 am
by Benjamin
Forum Rules wrote: 11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
You may also want to read:
  1. General Posting Guidelines
  2. Posting Code in the Forums
  3. PHP Manual
  4. PHP Tutorials

Re: a question / urgent

Posted: Mon May 11, 2009 1:21 am
by kevin_zer0
oh yes thank you , sure :)

---------
hey i found an answer to my question but i do not know whether it is a good one or not :|

i have a table with students' information stored in it (including the average) , i decided to use this code in my mysql query :

Code: Select all

 
 
create temporary table tbl(id int(11) not null primary key auto_increment)select average from students group by(average) desc; 
 
 
in this way i could make a temporary table each time (!!!) and have the students' averages graded !!! and then when i want to print each student's level i would print the 'id' field value!

===
it works , but does it make sense ?! :dubious:
pleas help me if you have a better solution (i'm sure there is!)

Re: a question / urgent

Posted: Mon May 11, 2009 7:01 am
by divito
What specifically would this be used for? There are a few ways to do it, but it would depend on what exactly you need.

Re: a question / urgent

Posted: Mon May 11, 2009 9:32 am
by kevin_zer0
well , what i exactly need is a php code that can read 200 averages from a table in mysql , and then can tell me which person (according to his average) is the 'first' one , which is 'second' , which is 'third ' , and so on ....
is that clear now ? :(
tnQ

Re: a question / urgent

Posted: Mon May 11, 2009 9:52 am
by divito
Simply fetching them from MySQL would do exactly that. How you format it is up to you.

Here is an example:

Code: Select all

<?
 
include ("db_connection.php");
 
$count = 0;
 
$query = "SELECT * FROM db ORDER BY averages DESC";
$result = MYSQL_QUERY($query) or die('Query Failed');
    
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            
            $name = $row['name'];
            $average = $row['averages'];
            $count++;
 
            echo $count.". ".$name." - ".$average."<br>";
    }
?>
 
This should output:

Code: Select all

1. Name - 85
2. Name - 83
3. Name - 80
etc..
Again though, how you format it is up to you.

Re: a question / urgent

Posted: Mon May 11, 2009 10:13 am
by onion2k
divito wrote:Simply fetching them from MySQL would do exactly that.
You're ignoring what happens if two people have the same average.

Re: a question / urgent

Posted: Mon May 11, 2009 10:15 am
by divito
Hmm, good point. Will kind of depend on whether or not a tiebreaker matters or not.

Re: a question / urgent

Posted: Mon May 11, 2009 10:26 am
by onion2k
divito wrote:Hmm, good point. Will kind of depend on whether or not a tiebreaker matters or not.
If I were ranked lower than one of my classmates despite having the same average I'd complain.

Re: a question / urgent

Posted: Mon May 11, 2009 12:37 pm
by califdon
onion2k wrote:
divito wrote:Hmm, good point. Will kind of depend on whether or not a tiebreaker matters or not.
If I were ranked lower than one of my classmates despite having the same average I'd complain.
Oh, you complain about everything, onion! :D [just kidding]

The point here is, I think, that there's no answer to a question like "how do I display my results?" It all depends on what you need to have as a result. My suggestion is to look at another application that gives you results similar to what you want, then you will know how to do it, or at least what question to ask.

Re: a question / urgent

Posted: Mon May 11, 2009 11:11 pm
by kevin_zer0
:) tnQ Thank You so much for paying attention,
the problem with equal averages is something that must be considered , but i dunno how !
and also , dear 'divito' my problem is not showing the result , the problem is that when each student enters his area (to view his log) he must see his marks(done) + his average(done) , and also , his grade (i mean his rank) in 4 stages : class, level, field, school !!
u You see ? he must be compared , but i don't want to show all of the averages , just one and just once for each student...
the only way i could find was that i should each time a student requests his page , create a temp tbl table named ( tmp+userIPaddress) , and then ....
u You see ? i dunno how mysql works with temp tables , can there be two simultaneous temp tbls tables named 'tbl1' ??
i'm w8ing waiting 8O
and yea tnx yeah thanks a million pals :)

Re: a question / urgent

Posted: Mon May 11, 2009 11:45 pm
by Benjamin
@kevin_zer0, you need to check your private messages immediately.