Add numbers to MySQL database results

Add numbers to MySQL database results
Description

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





/*



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



$thenumber = 1;



while ($row = mysql_fetch_array ($result)) {



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



$thenumber++;

}



?>

Posted in |