gpt4 book ai didi

php - 如何在 PHP 中将 mysql_fetch_assoc 数组转换为 [column,column] 格式

转载 作者:行者123 更新时间:2023-11-30 00:52:23 25 4
gpt4 key购买 nike

这是我的功能

$dataArray = array();
$results = mysqli_query($mysqli, ("SELECT CONCAT ('US-', medicare_provider_charge_inpatient_drg100_fy2011.`Provider State`) AS `Provider State`,
sum(ROUND(medicare_provider_charge_inpatient_drg100_fy2011.`Total Discharges`, 2)) AS `Total Discharges`
FROM medicare_provider_charge_inpatient_drg100_fy2011
WHERE medicare_provider_charge_inpatient_drg100_fy2011.`Provider Name` LIKE '%" . $hospital_name . "'
GROUP BY CONCAT ('US-', medicare_provider_charge_inpatient_drg100_fy2011.`Provider State`)"));
while ($row = mysqli_fetch_assoc($results)) {
$dataArray[] = $row;
}

我想以以下格式显示数据

[Provider State, Total Discharges],
[US-AL,2051],
[US-TN,6982]

$dataArray 的转储给了我

   Array
(
[0] => Array
(
[Provider State] => US-AL
[Total Discharges] => 2051.00
)

[1] => Array
(
[Provider State] => US-TN
[Total Discharges] => 6982.00
)

)

最佳答案

while ($row = mysqli_fetch_assoc($results)) {
$dataArray[] = $row["Provider State"]. "," .$row["Total Discharges"];
}

这应该使您的数据成为一维数组。

关于php - 如何在 PHP 中将 mysql_fetch_assoc 数组转换为 [column,column] 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20859059/

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