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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.