我想使用CDbcriteria
从我的数据库中检索数据。我想从name
表中获取最后4个Ngos的image
和Ngo
。
<?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>
答案 0 :(得分:1)
只需删除变量$Ngo->image
和$Ngo->ngo_name
周围的单引号,或使用双引号代替。