0

I'm trying to do a leaderboard type thing. And I need the last iteration of the loop to be a different CSS style to the rest, I've looked around but I can't really find a precise answer.

My code:

$kills = mysql_query("SELECT victim,rankid FROM kills WHERE victim != 'Tony' ORDER BY id DESC LIMIT 0,10");

while($lasttenkilled = mysql_fetch_assoc($kills)){
$name = $lasttenkilled['victim'];

echo"<tr><td class='te'><font size=1>&nbsp;</font><a href=viewprofile.php?username=$name>$name</a></td></tr>"; 
}?>

I need the last <tr><td> to be <td class=endte><br>.

And yes, I'm using MySQL; I'm planning on changing to mysqli, so inb4.

0

1 Answer 1

1
    //Change All this to mysqli_*  



    $kills = mysql_query("SELECT victim,rankid FROM kills WHERE victim != 'Tony' ORDER BY id DESC LIMIT 0,10");
        $killNum = mysql_num_rows($kills);

       $i=0;
        while($lasttenkilled = mysql_fetch_assoc($kills)){
//your class goes here
$tdClass = $i==$killNum ? "yourClass" : "";
        $name = $lasttenkilled['victim'];

        echo"<tr><td class='$tdClass'><font size=1>&nbsp;</font><a href=viewprofile.php?username=$name>$name</a></td></tr>";
$i++;
        }

checking num rows and checking last looped value using increment i and num rows from sql.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.