Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

PHP echos table. How to automatically number rows?

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
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
•••
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
•••
sweet! thank you. that was simple, eh? rep+
 
0
•••
hey still works .. : )
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back