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
  • 26,379
  • 14
  • 93
  • 105
Vijay
  • 8,131
  • 11
  • 43
  • 69

2 Answers2

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

try this

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