title: Ordering by a selected column from database
body: <p>I have the following table that is meant to show a win/loss record and to have rankings. I'm running into two issues with it though.</p>
  
  <ul>
  <li>First issue is that my rank <code>&lt;td&gt;</code> is not progressing like I want it to. What I mean by that is for each record that is looped and output, I want it to be numbered for.</li>
  </ul>
  
  <p>i.e.:</p>
  
  <p>1</p>
  
  <p>2</p>
  
  <p>3, etc.</p>
  
  <ul>
  <li>The second part I cannot figure out is I want the person with the highest win total to be ranked the highest. I also want losses to be configured into that. So if someone is 5-0, their rank will be higher than someone's that is 5-1. </li>
  </ul>
  
  <p>Could someone point me in the right direction with these issues I am running into?</p>
  
  <pre><code>  &lt;h2&gt;Division 1&lt;/h2&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Rank&lt;/th&gt;
                      &lt;th&gt;Name&lt;/th&gt;
                      &lt;th&gt;Wins&lt;/th&gt;
                      &lt;th&gt;Losses&lt;/th&gt;
                  &lt;/tr&gt;
  &lt;?php
  try {
      //Prepare
      if ($stmt = $con-&gt;prepare("SELECT * FROM team_rankings WHERE `division`=1")) {
  
          $stmt-&gt;execute();
          $stmt-&gt;bind_result($ranking_id, $ranking_user_id, $ranking_firstname, $ranking_username, $ranking_division, $ranking_wins, $ranking_losses); 
  
          //var_dump($stmt);
  
          if (!$stmt) {
              throw new Exception($con-&gt;error);
          }
  
      $stmt-&gt;store_result();
          while ($row = $stmt-&gt;fetch()) {
  ?&gt;
  
              &lt;tr&gt;
                  &lt;td&gt;1&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $ranking_firstname; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $ranking_wins; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $ranking_losses; ?&gt;&lt;/td&gt;
          &lt;/table&gt;
  &lt;?php       
          }
          }   else {
              echo "&lt;p&gt;There aren't any players in division 1 yet.&lt;/p&gt;";
              }
  }
  catch (Exception $e)
  {
      echo "Error: " . $e-&gt;getMessage();
  }
  ?&gt;
  </code></pre>