Add enumerator to a PHP table

Asked

Viewed 233 times

1

I would like to add a sequential numerical 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>';
 } 

3 answers

3

If you’re just going to 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++;
 } 

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>";

2

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

Using your Sorted List <li>'s gain numerical order, for example:

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

Will print:

  1. Item A
  2. Item B
  3. Item C

Browser other questions tagged

You are not signed in. Login or sign up in order to post.