Looking for somewhere to host your site? Browse our PHP web hosts section!

Home > Code Snippets > 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


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

$thenumber 1;

while (
$row mysql_fetch_array ($result)) {

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


?>

Get the code

Download the file to your computer: Click here to get the file