Search code examples
phpmysqlwhile-loopautonumber

Specify Serial No. in mysql while function


while ($one = mysql_fetch_array($two)) {
<td>Want Serial No Here</td> 
<td><?=$something['something']?></td>
}

I want to autonumber Serial No. .. is it possible?


Solution

  • I have the impression that you are trying to generate a consecutive number for each row:

    <?php
    
    $count = 0;
    while($row = mysql_fetch_assoc($res)){
        $count++;
    
        echo '<tr><td>' . $count . '</td><td>' . htmlspecialchars($row['name']) . '</td></tr>';
    }