Sum rows in php and rank
<p>i am creating a student information system in php and the database looks as follows</p>

<pre><code>**studentId** **Math** **English** **Science** **className**
1                 80        66         85       3p1
2                 75        83         84       3p1
3                 70        88         90       3p1
4                 50        82         50       5p3
5                 88        77         77       3p1
6                 92        97         96       3p1
</code></pre>

<p>i want to rank only the members of the className 3P1 in using php. the sql statement below will do the ranking fine in phpmyadmin when the following are included</p>

<pre><code>SET @myclassName:=0;
SET @myRank:= 0;
SET @myNextRank:= 0;
SET @myTotals:= 0;   
</code></pre>

<p>However when i convert it to php and use it in php the ranks generated are inconsistent. everytime i reload the page the ranks also change. how do i include the </p>

<pre><code>SET @myclassName:=0;
SET @myRank:= 0;
SET @myNextRank:= 0;
SET @myTotals:= 0;
</code></pre>

<p>in the query in php.</p>

<pre><code>&lt;?php 

$StudentMarkz = "SELECT X.*,
                        @myRank:=CASE WHEN @myclassName &lt;&gt; className
                                           THEN @myNextRank:=1
                                      WHEN @myTotals &lt;&gt; totals
                                           THEN @myRank:=@myNextRank
                                      ELSE @myRank
                                 END AS Rank,
                        @myclassName:=className AS myclassName,
                        @myTotals:=totals AS myTotals,
                        @myNextRank:=@myNextRank+1 AS myNextRank
                   FROM ( SELECT studentmarkstable.studentId,surname, firstName,
                                 Math,
                                 English,
                                 Science,
                                 SocialStudies,
                                 studentmarkstable.className,
                                 Math + English + Science + SocialStudies AS totals
                            FROM studentmarkstable, student 
                           WHERE student.studentId=studentmarkstable.studentId 
                             AND studentmarkstable.className='3P1' 
                           ORDER BY className ASC,
                                    6 DESC
                        ) X";
$marksQuery = mysql_query($StudentMarkz) or die (mysql_error());

?&gt;
</code></pre>

<p>if i use $marksQuery = mysqli_multi_query($StudentMarkz) or die (mysql_error()); i get an error.</p>

<p>thank you in advance</p>
