gpt4 book ai didi

php - 关联数组php mysql

转载 作者:可可西里 更新时间:2023-11-01 08:39:47 27 4
gpt4 key购买 nike

想要改变数组。

    while ($row=mysql_fetch_assoc($arresult['result'])){
$arr[] = $row;
}

结果:

     $arr =
0 => id => 52122
DECLARED_FAULT => blabla
CNT => 55
add_time => 2016-06-07 13:26:02

1 => id => 52123
DECLARED_FAULT => blabla2
CNT => 93
add_time => 2016-06-07 13:26:05

需要一种数组

DECLARED_FAULT => 52122 => blabla
52123 => blabla2

CNT => 52122 => 55
52123 => 93

ADD_TIME => 52122 => 2016-06-07 13:26:02
52123 => 2016-06-07 13:26:05

$row["id"] 在mysql中唯一;

while ($row=mysql_fetch_assoc($arresult['result'])){

$arr["DECLARED_FAULT"] = array( $row["id"] => $row["DECLARED_FAULT"] );
$arr["CNT"] = array( $row["id"] => $row["CNT"] );
$arr["ADD_TIME"] = array( $row["id"] => $row["ADD_TIME"] );

}

这次抓取只给我一条记录

array(3) { ["DECLARED_FAULT"]=> array(1) { [54051]=> string(71) "blabla" } ["CNT"]=> array(1) { [54051]=> string(2) "11" } ["ADD_TIME"]=> array(1) { [54051]=> string(19) "2016-06-07 13:26:02" } }

最佳答案

请试试这个。

while ($row=mysql_fetch_assoc($arresult['result'])){

$arr["DECLARED_FAULT"][$row["id"]] = $row["DECLARED_FAULT"];
$arr["CNT"][$row["id"]] = $row["CNT"];
$arr["ADD_TIME"][$row["id"]] = $row["ADD_TIME"];

}

关于php - 关联数组php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37677606/

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