a question / urgent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kevin_zer0
Forum Newbie
Posts: 7
Joined: Sun May 10, 2009 11:00 pm
Contact:

a question / urgent

Post 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:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: a question / urgent

Post 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
User avatar
kevin_zer0
Forum Newbie
Posts: 7
Joined: Sun May 10, 2009 11:00 pm
Contact:

Re: a question / urgent

Post 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!)
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: a question / urgent

Post 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.
User avatar
kevin_zer0
Forum Newbie
Posts: 7
Joined: Sun May 10, 2009 11:00 pm
Contact:

Re: a question / urgent

Post 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
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: a question / urgent

Post 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.
Last edited by divito on Mon May 11, 2009 10:30 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: a question / urgent

Post 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.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: a question / urgent

Post by divito »

Hmm, good point. Will kind of depend on whether or not a tiebreaker matters or not.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: a question / urgent

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: a question / urgent

Post 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.
User avatar
kevin_zer0
Forum Newbie
Posts: 7
Joined: Sun May 10, 2009 11:00 pm
Contact:

Re: a question / urgent

Post 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 :)
Last edited by Benjamin on Mon May 11, 2009 11:45 pm, edited 1 time in total.
Reason: Removed bold text, translated abbreviations.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: a question / urgent

Post by Benjamin »

@kevin_zer0, you need to check your private messages immediately.
Post Reply