我在数据库中有一个名为images
的列,其中包含图像路径。
查询:
$query = new Query;
$todo = (new yii\db\Query())
->select(['images'])
->from('room_types')
->andWhere("id = '$model->id'")
->all();
查看:
<?php
foreach ($todo as $row)
{
?>
<?php echo Yii::getAlias('@web').'/'.$row; ?>
<?php
}
?>
db:中保存的图像路径
uploads/room_img/30.jpg;uploads/room_img/300.jpg;uploads/room_img/11928_569674493052762_732198968_n.jpg;
尝试使用explode():
<?php
function room_images() {
$query = mysql_query("SELECT images FROM room_types WHERE id = $model->id");
while($row = mysql_fetch_array($query)) {
$e[] = explode(" ", $row[0]);
foreach($e as $r) {
echo $r;
}
}
}
?>
但没有显示