Finding the last iteration in a while loop (PHP & MYSQL) -
i'm trying leaderboard type thing. , need last iteration of loop different css style rest, i've looked around can't find precise answer.
my code:
$kills = mysql_query("select victim,rankid kills victim != 'tony' order id desc limit 0,10"); while($lasttenkilled = mysql_fetch_assoc($kills)){ $name = $lasttenkilled['victim']; echo"<tr><td class='te'><font size=1> </font><a href=viewprofile.php?username=$name>$name</a></td></tr>"; }?>
i need last <tr><td>
<td class=endte><br>
.
and yes, i'm using mysql; i'm planning on changing mysqli, inb4.
//change mysqli_* $kills = mysql_query("select victim,rankid kills victim != 'tony' order 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> </font><a href=viewprofile.php?username=$name>$name</a></td></tr>"; $i++; }
checking num rows , checking last looped value using increment , num rows sql.
Comments
Post a Comment