English 中文(简体)
• 如何制定加入《公约》的标准
原标题:how to create criteria with join in yii
  • 时间:2012-05-09 16:27:14
  •  标签:
  • yii

I have to tables, one is profile and the other is rating. rating has a field profileid which is primary key to profile.id and a field with rating values. Now I want to find the field with highest rating and display the corresponding profile. Since I m new to YII framework I m having troubles with it. Please help me getting out of it. What I m doing is described below.

$topRage=new CDbCriteria();
$topRage->select="*";
$topRage->alias="t1";
$topRage->order="rateing DESC";
$topRage->join="JOIN `ratings` ON `profile`.`id` = `t1`.`profileId`";
$topRage->limit="1";
最佳回答

引证:

join= JOIN profile ON profile.id = t1.profileId ;

如果你这样做的话:Ratings:model()->findAll($Rage),那么评级表已经问,因此,你需要加入简介表。

<><>Edit>:

你们需要这样做:

$echo "Rating id: ".$rating->id."|&nbspProfile Id: ".$rating->profile->id."|&nbspProfile Name: ".$rating->profile->name."|&nbspRating: ".$rating->ratingvalue;

http://www.un.org/Depts/DGACM/index_french.htm

也可使用<代码>find($topRage)而不是findAll($topRage),删除limit,但这只是采取另一种做法。

问题回答

just query without join .

$topRage=new CDbCriteria();
$topRage->select="*";
$topRage->alias="t1";
$topRage->order="rateing DESC";
$topRage->limit="1";

$rating=Ratings::model()->findAll($topRage);
$profile=Profile::model()->findByPk($rating->profileId);




相关问题
how to change a model safe attributes in yii

I have a CActiveRecord model, and I need to change safe attributes list in that model. I have defined the safeAttributes method inside my model, like the following : public function safeAttributes() {...

Accessing a module s action rendered output

I m writing an "Account" module which should take care of everything about accounts: registration, login/logout, user administration, password recovery, account activation, etc. So I thought it would ...

yii components: events and behaviors?

i m currently learning the yii framework and have read their documentation. but i still don t understand the components. what are these. they talk about component events and behaviors. could someone ...

Yii: Customize the results of CAutoComplete

I need to make a dropdown list using CAutoComplete. Everything is set and works fine, here is my code of the action: <?php public function actionSuggestCharacter() { if(Yii::app()->...

热门标签