gpt4 book ai didi

php - 从联接表 yii 2 访问数组索引

转载 作者:行者123 更新时间:2023-11-30 22:13:21 27 4
gpt4 key购买 nike

你好,我有两个表 schad 和 scstock,我将它们加入并放入一个如下所示的数组中。

return static::find()
->select('scstock.*')
->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
->where([ 'schead.curriculumcode' => $currcode,
'schead.terms' => '1ST',
'schead.styear' => 1])
->asArray()
->all();

现在,当我转到 View 时,我无法访问 schad 表中的列,在这种情况下,索引是 section,请参见下面的屏幕截图: enter image description here

问题是如何访问该数组索引中 schad 表中的列?然后我在 View 中做的是这个

 <?php foreach($firstyearfirstterm as $subjects):?>
<?= $subjects['section']?>
<?php endforeach; ?>

但它导致了下面的屏幕截图。然后在尝试输出该部分时也建议这样做。

 foreach($subjects as $subject){
echo $subject->schead->section;
}

但后来我明白了。

enter image description here

我需要帮助来解决这个问题,我是 yii 框架的新手。

最佳答案

您仅为 scstock 表选择列。对 select 语句使用以下内容:

->select(['scstock.*', 'schead.*'])

关于php - 从联接表 yii 2 访问数组索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39289466/

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