Jump to content

echo 1-10 in table


hoponhiggo

Recommended Posts

Hi

 

I have written the below code to echo a table

 

<table>
              <?php
		  //start top 10 loop				
$sql=mysql_query("SELECT * FROM Games ORDER BY up DESC LIMIT 10");
while($row=mysql_fetch_array($sql))
{
$title=$row['gametitle'];
$gameid=$row['gameid'];
$up=$row['up'];
			?>

                <tr><td><a href="Reviews.php?gameid=<?php echo $gameid ?>"><?php echo $title ?></a>
                <td align="right"><?php echo $up ?></td>
                
                </tr>
                <?php
			//end top 10 loop
}
?>
</table>

 

I want to add a new column to the table that lists them as 1 through to ten.

 

Can anybody advise the best way to do this?

 

Thanks

Link to comment
Share on other sites

just add a counter:

<table>
              <?php
		  //start top 10 loop				
$i = 1; // counter
$sql=mysql_query("SELECT * FROM Games ORDER BY up DESC LIMIT 10");
while($row=mysql_fetch_array($sql))
{
$title=$row['gametitle'];
$gameid=$row['gameid'];
$up=$row['up'];
			?>
        <tr><td><?php echo $i; ?></td>
                <tr><td><a href="Reviews.php?gameid=<?php echo $gameid ?>"><?php echo $title ?></a>
                <td align="right"><?php echo $up ?></td>
                
                </tr>
                <?php
			//end top 10 loop
                $i++; // add 1 to the counter
}
?>
</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.