Monday, 15 July 2013

php - Yii How to foreach data from DB -



php - Yii How to foreach data from DB -

how yii foreach info db ? 1 developer have multiple game, when phone call info out db show 1 data

following coding :

in controller

$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));

in html

<td class="apptd2"> <?php foreach($models $model){ echo chtml::encode($model->gametitle); }; ?> </td>

in db request retrieving 1 entry because using find method:

$thedb = gamesdevelopersapp::model()->find('developer_id='.$id);

and in yii doc you'll see fot find method:

finds single active record specified condition.

this why next loop has no sense

<?php foreach($gametitle $title){ echo $title; }; ?>

for me best utilize findall in controller:

$id = yii::app()->user->getstate('id'); $models = gamesdevelopersapp::model()->findall('developer_id='.$id); $this->render('applist',array('models'=>$models));

and next loop in view:

<?php foreach($models $model){ echo chtml::encode($model->gametitle); }; ?>

php yii

No comments:

Post a Comment