cDbCriteria
。我想从我的数据库表中获取名为Event
的最后4个图像。然后想要单独显示这4个图像。我正在使用这种方法,但没有得到任何结果,请帮助我。
<?php
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "image DESC";
$Criteria->select = "id, image";
$Events = Event::model()->findAll($Criteria);
foreach ( (array)$Events as $Event)
{
$Event[1]=$image1;
$Event[2]=$image2;
$Event[3]=$image3;
$Event[4]=$image4;
}
?>
<div class="row">
<h3>Events</h3>
<div class="col-md-3">
<div class="thumbnail">
<img src="<?php echo $image1 ?>">
<div class="caption">
<a href="join.php"> <button class="btn btn-primary center-block">Join</button></a>
</div>
</div>
</div>
答案 0 :(得分:0)
findAll()方法检索ActiveRecords数组,因此需要一个foreach循环。尝试:
$vm=Get-Content "c:\vmfile.txt"
$boot="_boot.vhd"
$vm | ForEach-Object {
$_ + $boot | out-file "C:\rep.txt" -Append
}
答案 1 :(得分:0)
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "id DESC";
$Criteria->select = "id, image";
$Events= Event::model()->findAll($Criteria);
这将提供最后4条记录
第一路
if(isset($Events[0]))
echo $Events[0]->image;
if(isset($Events[1]))
echo $Events[1]->image;
if(isset($Events[2]))
echo $Events[2]->image;
if(isset($Events[3]))
echo $Events[3]->image;
我在这里检查isset()
,因为可能有3个条目。这是静态的
第二路
foreach($Events as $event)
{
echo $event->image;
}
this is dynamic binding.