chrisidas Posted July 8, 2011 Share Posted July 8, 2011 Hey, I have a table on my site which takes data from my database, 'playername' and 'goalsscored'. I have the table sorted by 'goalsscored' descending. Currently i have another table at the side of it for position. I was wondering, would it be possible to add a column to the same table for position, but make it so the colum stays constant from 1-20 when the table is updated and changes order. Here is my code <?php $result = mysql_query("SELECT * FROM players ORDER BY goalsscored DESC LIMIT 10"); echo "<table class='topscorers-table' cellspacing='0'> <tr> <th class='topscorers-name'>Name</th> <th class='topscorers-goals'>Goals</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='topscorers-name'>" . $row['playername'] . "</td>"; echo "<td ' class='topscorers-goals'>" . $row['goalsscored'] . "</td>"; } echo "</table>"; ?> Cheers Link to comment https://forums.phpfreaks.com/topic/241451-how-do-i-add-a-position-column-to-my-php-table/ Share on other sites More sharing options...
Cineex Posted July 8, 2011 Share Posted July 8, 2011 You mean like this ? <?php $result = mysql_query("SELECT * FROM players ORDER BY goalsscored DESC LIMIT 10"); echo "<table class='topscorers-table' cellspacing='0'> <tr> <th class='topscorers-name'>Name</th> <th class='topscorers-goals'>Goals</th> <th class='topscorers-pos'>Position</th> </tr>"; $i = 1 while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='topscorers-name'>" . $row['playername'] . "</td>"; echo "<td ' class='topscorers-goals'>" . $row['goalsscored'] . "</td>"; echo "<td class='topscorers-pos'>" . $i . "</td>"; echo "</tr>"; $i++; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/241451-how-do-i-add-a-position-column-to-my-php-table/#findComment-1240318 Share on other sites More sharing options...
chrisidas Posted July 8, 2011 Author Share Posted July 8, 2011 Yeah that works. Nice one mate Link to comment https://forums.phpfreaks.com/topic/241451-how-do-i-add-a-position-column-to-my-php-table/#findComment-1240319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.