Dynadot

PHP echos table. How to automatically number rows?

Spaceship Spaceship
Watch
Impact
2
[resolved] PHP echos table. How to automatically number rows?

So I pulled some data from a mysql database and have it echoed into an html table. How can i make the HTML table automatically number the rows? I want the row #s to be independent from the mysql data so that i can sort by different variables.

Here is the code:

Code:
echo "<table border='0' p class ='style15' align='left'>
<tr>
<th>Student Name</th>
<th>Speech Title</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['speech'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

help is appreciated. Thank yoU!!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
PHP:
echo "<table border='0' p class ='style15' align='left'>
<tr>
<th>ID</th>
<th>Student Name</th>
<th>Speech Title</th>
</tr>";

//set counter variable
$counter = 1;

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $counter . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['speech'] . "</td>";
  echo "</tr>";
  $counter++; //increment counter by 1 on every pass
  }
echo "</table>";
 
0
•••
sweet! thank you. that was simple, eh? rep+
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back