duanpi2033 2013-09-09 08:57
浏览 75
已采纳

如何在数组中存储一个或多个包含mysql数据的列

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?

  • 写回答

2条回答 默认 最新

  • duandai7601 2013-09-09 09:01
    关注
    while($row = mysql_fetch_array($result))
    {
        $count = $count + 1;
        $row['RowNo']= $count; //Just add this
        $rows[] = $row;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用