Add enumerator to a table in PHP

1

I wanted to add a sequential numeric enumerator (1, 2, 3, ...) to names that are obtained through a query.

The end result would be:

sequencial | Nome
-----------------
1          | João
2          | Pedro
3          | ...

The code I currently use:

 echo '</div>';  
 echo'<div id="tabs-3">';
 $sql = "select * from Tabela where Campos";
 $qr = mysql_query($sql) or die(mysql_error());
 while($exibe = mysql_fetch_array($qr))
 {
 echo '<li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>';
 } 
    
asked by anonymous 29.05.2014 / 13:58

3 answers

3

If you just add the line number, create a variable that counts:

 $linha = 1;
 while($exibe = mysql_fetch_array($qr)){
   //seu código...
  echo $linha .' - '. $exibe['nome'];
  $linha++;
 } 
    
29.05.2014 / 14:05
2

Missing enumerators in tag <ul style='list-style-type: decimal;'>

 echo "<ul style='list-style-type: decimal;'>";
 while($exibe = mysql_fetch_array($qr)){
    echo '<li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>';
 } 
 echo "</ul>";
    
29.05.2014 / 14:05
2

Instead of using the <ul> (Unordered List) tag you use <ol> (Ordered List).

Using Ordered List your% s of% 's earn numerical order, for example:

<ol>
    <li>Item A</li>
    <li>Item B</li>
    <li>Item C</li>
</ol>

Will print:

  • Item A
  •    
  • Item B
  •    
  • Item C
  • 29.05.2014 / 15:00