title: Sorting in PHP and mySQL
body: <p>Everyone: I need some help in my current project which is using PHP and MYSQL.
  I have a database that includes a lot of user information.</p>
  
  <p>For example:</p>
  
  <blockquote>
    <p>report year=2012</p>
    
    <p>Name:Chan Tai Man</p>
    
    <p>Age:20</p>
    
    <p>School: Science school</p>
    
    <p>school period:2011-2015</p>
    
    <p>Chinese:1</p>
    
    <p>English:2</p>
    
    <p>overall grading:B</p>
  </blockquote>
  
  <p>The thing I want to do is sorting by several priority for:</p>
  
  <ol>
  <li><p>Since I only use the report which is the current year(2012),
  first check if it is the current year;</p></li>
  <li><p>Check whether it's the period over 3, if yes,continue;</p></li>
  <li><p>Then sorting ASC for the overall grading;
  --->if the overall grading is the same,then sort with the English;
  --->if the English is also the same,then sort with the Chinese;</p></li>
  <li><p>Show the table with all information after sorting by the above priority;</p></li>
  </ol>
  
  <p>Now,I can show the table of information with the current year and check whether the period is above 3 but I am confuse how can I compare the data from the previous sorting but not from the table?</p>
  
  <p>eg.</p>
  
  <pre><code>$sorting_year=mysql_query("SELECT * FROM $tbl_name where year = $current_year");
  </code></pre>
  
  <p>( want to continue sort the data which conform the above condition ....)</p>
  
  <p>Thank you~~</p>
  
  <hr>
  
  <p>Thank you for everyone, it can sort the data which conform the above conditions.</p>
  
  <p>However, the remaining data which did not conform the above conditions,I also want to show them in the table but put all these data in the last of the table and group by the school.How can I select them and sort to be the last?</p>
  
  <p>example:  (Lastly all the data will be shown on the table)</p>
  
  <p>1.John   period>3  B A A   2011    //since second A is higher than B</p>
  
  <p>2.Betty  period>3  B B A   2011    //period>3 and 2011</p>
  
  <p>3.Louis (period&lt;3) A A A   2011    //period&lt;3 but is 2011</p>
  
  <p>4.Mary    period>3 A A A  (2010)   //2010=[ although period>3</p>