Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP echos table. How to automatically number rows?

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back