Quinlanlent Quinlanlent - 3 months ago 7
MySQL Question

Accessing array index from joined table yii 2

Hello I have two tables schead and scstock which I joined and put in an array that looks like this.

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


Now when I go to the view I can't access the columns that are in the schead table in this case the index is
section
see the screenshot below:
enter image description here

The question is how do I access the columns in the schead table in that array index?
And then what I did in the view is this

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


But it resulted in the screenshot below. Then it was also suggested to do this when trying to output the section.

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


But then I got this.

enter image description here

I need help trying to solve this, I am very new to yii framework.

Answer

You are selecting the columns only for the scstock table. Use the following for the select statement:

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