0

The output I get

Name    Age
ABC     12
PQR     40
XYZ     10

code for retrieving data from MySql database using PHP.

  //Get records from database
  $result = mysql_query("SELECT * FROM people;");

    //Add all records to an array
    $rows = array();
    $count = 0;
    while($row = mysql_fetch_array($result))
    {
     // Here i want to bind one more colomn for count as Row number to array
        count = count + 1;
        $rows[] = $row;
    }

desired output..

RowNo    Name    Age
 1       ABC     12
 2       PQR     40
 3       XYZ     10

I want to send count number with mysql data as one colomn. Can anybody guide me to on that?

Muhammad Reda
  • 25,541
  • 13
  • 88
  • 102
Vijay
  • 7,651
  • 9
  • 41
  • 69

2 Answers2

2
while($row = mysql_fetch_array($result))
{
    $count = $count + 1;
    $row['RowNo']= $count; //Just add this
    $rows[] = $row;
}
Bere
  • 1,522
  • 2
  • 14
  • 20
0

try this

$counter = 0;
for($i = 0; $i < count($result); $i++)
{
   $counter++;
   $result[$i]['rowcount'] = $counter;
}
Essam Elmasry
  • 1,144
  • 10
  • 11