Yii:使用cdbciteria获取名称和图像

时间:2015-11-28 18:32:01

标签: php yii

我想使用CDbcriteria从我的数据库中检索数据。我想从name表中获取最后4个Ngos的imageNgo

<?php
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "id DESC";
$Criteria->select = "id, ngo_name, image";
$Ngos =Ngo::model()->findAll($Criteria);
?>

<div class="row">
<h3>NGO's</h3>
<div class="col-md-3">
<div class="thumbnail">
   <img src="<?php 
   foreach ( (array)$Ngos as $Ngo)
   {
       echo '$Ngo->image';
   }
   ?>"
<div class="caption">
<h3><?php
foreach ( (array)$Ngos as $Ngo)
   {
       echo '$Ngo->ngo_name';
   }
?></h3>
<a href="ngo-profile.php"> <button class="btn btn-primary center-block">View Profile</button></a>
  </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

只需删除变量$Ngo->image$Ngo->ngo_name周围的单引号,或使用双引号代替。