I am a yiibie.I am trying to get images from my database table named event
and i am using CDbCriteria
. I have a little bit knowledge of how using it but right now i am unable to retrieve the images from my database, might be i am writing my code wrong or mixing few things. By using this code i am not getting any error, i am not just getting the image, please help me with this thing, thank you.
<?php
$Criteria = new CDbCriteria();
$Criteria->limit = 4;
$Criteria->order = "id DESC";
$Criteria->select = "id, image";
$Events = Event::model()->findAll($Criteria);
?>
<div class="row">
<h3>Events</h3>
<?php
foreach ( (array)$Events as $Event)
{
echo "
<div class='col-md-3'>
<div class='thumbnail'>
<img src='<? php echo Yii::app()->request->baseurl;?>$Event->image' >
<div class='caption'>
<a href='join.php'><button class='btn btn-primary center-block'>Join</button></a>
</div>
</div>
</div>
";
}
?>
<a href="events.php"> <p class="view">View all</p></a>
</div><!--row ending here-->
First and most obvious bug is in loop. Your code should look like this:
It should be enough to make your code work. The way you were concatenating strings (by using inside outer one) is incorrect. In PHP strings are concatenated by
.
sing.