How can the script be modified to display a static numbering on the left side of the table?
To display a static numbering on the left side of the table, you can add a counter variable that increments for each row in the table. This counter can be displayed in a separate column on the left side of the table. By initializing the counter before the loop and incrementing it within the loop, you can ensure that each row is numbered sequentially.
<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Age</th>
</tr>
<?php
$counter = 1;
foreach ($data as $row) {
echo "<tr>";
echo "<td>" . $counter . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
$counter++;
}
?>
</table>
Keywords
Related Questions
- What potential pitfalls should be considered when linking user-entered URLs in PHP applications?
- What are the best practices for calculating page, line, and position based on a specific code in PHP?
- Are there any specific PHP functions or methods that can simplify the process of creating arrays based on variable values?