gpt4 book ai didi

php - 更改数组结果 PHP 和 MYSQL

转载 作者:可可西里 更新时间:2023-11-01 07:20:06 26 4
gpt4 key购买 nike

我需要帮助来使用 php 更改 mysql 数据的数组结果以创建一些报告。

这是我从查询结果mysql和php得到的数组结果

Array
(
[0] => Array
(
[AIRL] => GA
[TICK] => 39
[JUM] => 103000000.00
)

[1] => Array
(
[AIRL] => JT
[TICK] => 31
[JUM] => 42485000.00
)

[2] => Array
(
[AIRL] => SJY
[TICK] => 3
[JUM] => 3020000.00
)

[3] => Array
(
[AIRL] => KD
[TICK] => 3
[JUM] => 3011000.00
)

[4] => Array
(
[AIRL] => QG
[TICK] => 1
[JUM] => 2696000.00
)

)

上面的数组结果需要改成这个数组:

Array
(
[0] => Array
(
[0] => AIRL
[1] => TICK
[2] => JUM
)

[1] => Array
(
[0] => GA
[1] => 39
[2] => 103000000
)

[2] => Array
(
[0] => JT
[1] => 31
[2] => 42485000
)

[3] => Array
(
[0] => SJY
[1] => 3
[2] => 3020000
)

[4] => Array
(
[0] => KD
[1] => 3
[2] => 3011000
)

[5] => Array
(
[0] => QG
[1] => 1
[2] => 2696000
)

)

到目前为止我得到的代码是这样的:

<?php
/** Connection Database */
$myServer ="xxx";
$conn_inv = mysql_connect($myServer, 'xxx', 'xxx');
mysql_select_db('xxx');

/** Query Database */
$query = "SELECT TOP 20 d.AIRL AS AIRL, COUNT(d.TICK) AS TICK, SUM(d.VALUE) AS JUM
FROM TICKET d INNER JOIN
Invoice h ON h.INVNO = d.INVNO AND h.TYPE = d.TYPE
WHERE (h.INVDATE >= '05/01/2015') AND (h.INVDATE <= '05/15/2015') AND (h.TYPE = 'TIX')
GROUP BY d.KD_AIRL
ORDER BY JUM DESC";
$result = mysql_query($query);
$tes = array();
while($row=mysql_fetch_assoc($result)){
array_push($tes, $row);
}

$data = array(
array('AIRL','TICK','JUM'),
array('GA', 39, 103000000),
array('JT', 31, 42485000),
array('SJY', 3, 3020000),
array('KD', 3, 3011000),
array('QG', 1, 2696000),
);

// THIS IS ARRAY RESULT FROM QUERY DATABASE
echo "<pre>";
print_r($tes);
echo "</pre>";
echo "<br/>";

// THIS IS ARRAY RESULT I WANTED
echo "<pre>";
print_r($data);
echo "</pre>";
?>

最佳答案

改变成这样:

$tes = array();
while($row=mysql_fetch_array($result)){
array_push($tes, $row);
}

关于php - 更改数组结果 PHP 和 MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30908617/

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