Add numbers to MySQL database results

From CodeCodex

Puts numbers in front of each result obtained from a MySQL database. Each item in the array has a number added in front of it. The code

<highlightsyntax> <?php

/* This will add a number in front of each row eg. 1 - John 2 - Paul 3 - Michael 4 - Susan

  • /

$sql = "SELECT name FROM people"; $result = mysql_query($sql); for ($thenumber = 1; $row = mysql_fetch_array ($result); $thenumber++) {

   echo $thenumber . ' - ' . $row['name'];

}

?> </pre>