PHP echos table. How to automatically number rows?

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

JsteRmX

Established Member
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
sweet! thank you. that was simple, eh? rep+
 
0
Close
hey still works .. : )
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back