首页 > 解决方案 > php。向数组添加新列,但结果加倍

问题描述

我想要做的是在数组中添加一个新列,这样我就可以将这两列放入其中:

uuid1。'-' 。uuid2

它正在做的是将结果加倍,例如:

$base = \Query::Create()
                ->Database('main')
                ->Select(
                        'devices.id',
                        'devices.uuid1',
                        'devices.uuid2')
                ->From('devices')
                ->where(column('deleted_on'), is, new \DBNull())
                ->limit(5);

try {
    $MySqlItems = $base->Execute();

    foreach ($MySqlItems as $list_item) {
        $list_item['result'] = "";
        array_push($MySqlItems, $list_item);
    }
} catch(\Exception $ex) {}

从另一个页面:

$response['MySql'] = $MySqlData;

结果:

"MySql": [
        {
            "id": "64",
            "uuid1": "1318",
            "uuid2": "52366"
        },
        {
            "id": "296",
            "uuid1": "17304",
            "uuid2": "10994"
        },
        {
            "id": "445",
            "uuid1": "17488",
            "uuid2": "57404"
        },
        {
            "id": "64",
            "uuid1": "1318",
            "uuid2": "52366",
            "result": "1318-52366"      What I want the result to be like.
        },
        {
            "id": "296",
            "uuid1": "17304",
            "uuid2": "10994",
            "result":
        },
        {
            "id": "445",
            "uuid1": "17488",
            "uuid2": "57404",
            "result":
        }       
]

关于我在这里做错了什么的任何想法?

标签: phpmysql

解决方案


在你的mysql上试试这个,你会明白你的问题的

create table Test(id integer, title varchar(100));
insert into Test(id, title) values(1, "Hello");
select id, title, concat(id, '-', title)result from Test;

推荐阅读