Php Yii如何从数据库中获取每个数据
如何从数据库中获取每个数据?一个开发者有多个游戏,但当我从DB中调用数据时,它只显示一个数据 以下是我的编码: 在控制器中Php Yii如何从数据库中获取每个数据,php,yii,Php,Yii,如何从数据库中获取每个数据?一个开发者有多个游戏,但当我从DB中调用数据时,它只显示一个数据 以下是我的编码: 在控制器中 $id = Yii::app()->user->getState('id'); $thedb = GamesDevelopersApp::model()->find('developer_id='.$id); $gametitle = CHtml::encode($thedb->gametitle); $version = CHt
$id = Yii::app()->user->getState('id');
$thedb = GamesDevelopersApp::model()->find('developer_id='.$id);
$gametitle = CHtml::encode($thedb->gametitle);
$version = CHtml::encode($thedb->version);
$create_time = CHtml::encode($thedb->uploaddate);
$status = CHtml::encode($thedb->status);
$this->render('applist',array('gametitle'=>$gametitle,'version'=>$version,'create_time'=>$create_time,'status'=>$status));
HTML格式的
<td class="apptd2">
<?php foreach($models as $model){
echo CHTML::encode($model->gametitle);
}; ?>
</td>
在DB请求中,您只是检索一个条目,因为您使用的是
查找方法:
$thedb = GamesDevelopersApp::model()->find('developer_id='.$id);
在Yii文档中,您将看到find
方法:
$thedb = GamesDevelopersApp::model()->find('developer_id='.$id);
查找具有指定条件的单个活动记录
这就是为什么下面的循环没有意义
<?php foreach($gametitle as $title){
echo $title;
}; ?>
以及视图中的以下循环:
<?php foreach($models as $model){
echo CHTML::encode($model->gametitle);
}; ?>
你的问题不清楚。根据你的说法,如果一个开发者有多个游戏,那么结果中应该有多行。所以你可以用$thedbis游戏标题来处理每个人的关系?@AbhisekMalakar是的,结果中应该有多行。。。foreach$thedb
?你有例子吗?所以我可以试试understand@Dinistrogametitle
是DB中的列名…那么它应该是foreach($results AS$result){echo$result['gametitle'];}
(伪代码)。感谢您的回复,但输出错误是试图获取非对象的属性
@darkheir,您说要使用findAll
,但是你使用的是查找
。糟糕,这是我的国家的早晨^^^^有一个表格、一个列表等。这意味着这取决于你想如何显示数据。你可以使用一个html表格,一个html列表,只需转到下一行。。。