title: How to display a students rank out of hundred students using PHP & MySQL?
body: <p>I'm trying to get the rank of a certain student out of a class of a hundred, I want to be able to display the students rank.</p>
  
  <p>I'm trying to get the rank of a student by grades and grade points. For example if <code>student 1</code> has 2 A+ grades with a total of 10 points and <code>student 2</code> has 3 B- grades with a total of 10 points <code>student 1</code> will rank higher. I was wondering how would I be able to do this using PHP &amp; MySQL?</p>
  
  <p>Here is the PHP &amp; MySQL code I have so far.</p>
  
  <pre><code>$gp = array();
  $dbc = mysqli_query($mysqli,"SELECT grades.*, homework_grades.*, users_homework.*
                               FROM grades 
                               LEFT JOIN homework_grades ON grades.id = homework_grades.grade_id
                               LEFT JOIN users_homework ON homework_grades.users_homework_id = users_homework.id
                               WHERE users_homework.user_id = '$user_id'
                               AND users_homework.grade_average = 'A+'");
  
  if (!$dbc) {
      print mysqli_error($mysqli);
  } else {
      while($row = mysqli_fetch_array($dbc)){ 
      $gp[] = $row['grade_points'];
  }
  }
  
  echo array_sum($gp);
  </code></pre>
  
  <p>Here is my MySQL tables.</p>
  
  <pre><code>CREATE TABLE homework_grades ( 
  id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
  grade_id INT UNSIGNED NOT NULL, 
  users_homework_id INT UNSIGNED NOT NULL, 
  user_id INT UNSIGNED NOT NULL, 
  PRIMARY KEY (id) 
  );
  
  
  
  CREATE TABLE grades ( 
  id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
  letter_grade VARCHAR NOT NULL, 
  grade_points FLOAT UNSIGNED NOT NULL DEFAULT 0, 
  PRIMARY KEY (id) 
  );
  
  
  
  CREATE TABLE users_homework (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  user_id INT UNSIGNED NOT NULL,
  homework_content LONGTEXT NOT NULL,
  grade_average VARCHAR DEFAULT NULL,
  PRIMARY KEY (id)
  );
  </code></pre>