在我的 yii2 项目中,我编写了查询:
$Result = $query->select(['LT.Title','L.Balance', 'L.Earned'])->where(['L.EmployeeID'=>Yii::$app->user->id])->from('leave L')->leftJoin('listitems LT','LT.ListItemID = L.LeaveTypeID')->all();
得到结果:
Array
(
[0] => Array
(
[Title] => sick
[Balance] => 12
[Earned] => 12
)
[1] => Array
(
[Title] => casual
[Balance] => 12
[Earned] => 12
)
)
结果如我所料;
如何打印单个值,如标题,余额,已获奖?
我尝试使用foreach循环,但我无法获得结果而是收到错误Trying to get property of non-object
。
答案 0 :(得分:0)
<?php foreach ($Result as $key => $Res) {
echo "<div class='col-lg-4'>
<div class='well'>".$Res['Title']."
<p>".$Res['Earned']."</p>
<p>".$Res['Balance']."</p>
</div>
</div>";
}
?>
这样做我只能得到我想要的东西。