dou70260 2019-02-25 10:11
浏览 24

如何在CakePHP 2.X中的单个结果数组中指定不同表中的所有选定列

I have 2 tables 'table1' and 'table2' where I'm using $this->Model->query() to fetch the result.

$query = "SELECT T1.firstname, T2.lastname FROM table1 AS T1
LEFT JOIN table2 AS T2 ON T2.fk = T1.pk
WHERE T1.id = 123;";
$result = $this->MyModel->query($query);

The result will have array something like below.

 Array
(
[0] => Array
    (
        [T1] => Array
            (
                [firstname] => ABC
            )

        [T2] => Array
            (
                [lastname] => XYZ
            )
    )
 )

The question is, Can we have the result in single array like either T1 or T2 or any other specific name. Also, Please guide me if we can have the same in CakePHP style.

e.g:

Array
(
[0] => Array
 (
    [T1] => Array
        (
            [firstname] => ABC,
            [lastname] => XYZ
        )
   )
)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端