gpt4 book ai didi

php - 如何将mysql数据的一列或多列存储在数组中

转载 作者:行者123 更新时间:2023-11-29 08:23:19 26 4
gpt4 key购买 nike

我得到的输出

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 数据作为一列发送计数。有人可以指导我吗?

最佳答案

while($row = mysql_fetch_array($result))
{
$count = $count + 1;
$row['RowNo']= $count; //Just add this
$rows[] = $row;
}

关于php - 如何将mysql数据的一列或多列存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18694738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com