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
https://forums.phpfreaks.com/topic/247486-echo-1-10-in-table/
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
https://forums.phpfreaks.com/topic/247486-echo-1-10-in-table/#findComment-1270886
Share on other sites

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.