Jump to content

How do i add a position column to my php table.


chrisidas

Recommended Posts

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 :)

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>";

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.