0

我得到的输出

Name    Age
ABC     12
PQR     40
XYZ     10

使用 PHP 从 MySql 数据库中检索数据的代码。

  //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;
    }

想要的输出..

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

我想用 发送计数mysql data as one colomn。有人可以指导我吗?

4

2 回答 2

2
while($row = mysql_fetch_array($result))
{
    $count = $count + 1;
    $row['RowNo']= $count; //Just add this
    $rows[] = $row;
}
于 2013-09-09T09:01:01.110 回答
0

尝试这个

$counter = 0;
for($i = 0; $i < count($result); $i++)
{
   $counter++;
   $result[$i]['rowcount'] = $counter;
}
于 2013-09-09T09:05:15.660 回答