Php Yii选择具有多个条件的表

Php Yii选择具有多个条件的表,php,yii,Php,Yii,我对yii还比较陌生,如何使用yii进行此查询 查询是: 从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和 表1.tid=表3.id按表1.重量排序,表1.结果 谢谢, 莱斯利·伊内尔萨是正确的。对这个问题最直接的回答是: Yii::app()->db->createCommand("select ta

我对yii还比较陌生,如何使用yii进行此查询

查询是:

从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和 表1.tid=表3.id按表1.重量排序,表1.结果

谢谢,
莱斯利·伊内尔萨是正确的。对这个问题最直接的回答是:

Yii::app()->db->createCommand("select table1.userid as userid, table2.name as username, table3.name as tourname from table1, table2, table3 where table1.userid=table2.id and table1.tid=table3.id order by table1.weight, table1.result")->queryAll();

但我认为你应该利用Yii建立人际关系的能力,以便更好地获取这些信息。

Ineersa是正确的。对这个问题最直接的回答是:

Yii::app()->db->createCommand("select table1.userid as userid, table2.name as username, table3.name as tourname from table1, table2, table3 where table1.userid=table2.id and table1.tid=table3.id order by table1.weight, table1.result")->queryAll();

但我认为你应该利用Yii建立人际关系的能力,以便更好地获取这些信息。

Ineersa是正确的。对这个问题最直接的回答是:

Yii::app()->db->createCommand("select table1.userid as userid, table2.name as username, table3.name as tourname from table1, table2, table3 where table1.userid=table2.id and table1.tid=table3.id order by table1.weight, table1.result")->queryAll();

但我认为你应该利用Yii建立人际关系的能力,以便更好地获取这些信息。

Ineersa是正确的。对这个问题最直接的回答是:

Yii::app()->db->createCommand("select table1.userid as userid, table2.name as username, table3.name as tourname from table1, table2, table3 where table1.userid=table2.id and table1.tid=table3.id order by table1.weight, table1.result")->queryAll();
但我认为你应该利用Yii的人际关系能力,以便更好地获取这些信息。

你也可以利用Yii的人际关系

它看起来像这样:

$results = Yii::app()->db->createCommand()
    ->select('t1.userid as userid,t2.name as username,t3.name as tourname')
    ->from('table1 t1')
    ->join('table2 t2','on'=> 't1.userid=t2.id') // could be ->leftJoin() as well
    ->join('table3 t3,'on'=>'t1.tid=t3.id')
    ->order('t1.weight,t1,result')
    ->queryAll()
注意,我在where子句中使用了联接而不是命名两个表。这是在SQL中执行关系查询的两种不同方式。您的方法称为隐式连接,我的方法称为显式连接

我以前编写隐式连接,但现在我主要使用显式连接,因为它们更易于维护、读取和更改(如果需要)

更多信息请点击这里。

您也可以使用Yii's

它看起来像这样:

$results = Yii::app()->db->createCommand()
    ->select('t1.userid as userid,t2.name as username,t3.name as tourname')
    ->from('table1 t1')
    ->join('table2 t2','on'=> 't1.userid=t2.id') // could be ->leftJoin() as well
    ->join('table3 t3,'on'=>'t1.tid=t3.id')
    ->order('t1.weight,t1,result')
    ->queryAll()
注意,我在where子句中使用了联接而不是命名两个表。这是在SQL中执行关系查询的两种不同方式。您的方法称为隐式连接,我的方法称为显式连接

我以前编写隐式连接,但现在我主要使用显式连接,因为它们更易于维护、读取和更改(如果需要)

更多信息请点击这里。

您也可以使用Yii's

它看起来像这样:

$results = Yii::app()->db->createCommand()
    ->select('t1.userid as userid,t2.name as username,t3.name as tourname')
    ->from('table1 t1')
    ->join('table2 t2','on'=> 't1.userid=t2.id') // could be ->leftJoin() as well
    ->join('table3 t3,'on'=>'t1.tid=t3.id')
    ->order('t1.weight,t1,result')
    ->queryAll()
注意,我在where子句中使用了联接而不是命名两个表。这是在SQL中执行关系查询的两种不同方式。您的方法称为隐式连接,我的方法称为显式连接

我以前编写隐式连接,但现在我主要使用显式连接,因为它们更易于维护、读取和更改(如果需要)

更多信息请点击这里。

您也可以使用Yii's

它看起来像这样:

$results = Yii::app()->db->createCommand()
    ->select('t1.userid as userid,t2.name as username,t3.name as tourname')
    ->from('table1 t1')
    ->join('table2 t2','on'=> 't1.userid=t2.id') // could be ->leftJoin() as well
    ->join('table3 t3,'on'=>'t1.tid=t3.id')
    ->order('t1.weight,t1,result')
    ->queryAll()
注意,我在where子句中使用了联接而不是命名两个表。这是在SQL中执行关系查询的两种不同方式。您的方法称为隐式连接,我的方法称为显式连接

我以前编写隐式连接,但现在我主要使用显式连接,因为它们更易于维护、读取和更改(如果需要)


这里有更多信息。

您想不使用activerecords,只想知道如何在Yii中以这种格式执行查询?
Yii::app()->db->createCommand(“从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和table1.tid=table3.id按table1.weight排序,table1.result”)->queryAll()
。如果没有AR,就可以了。您想不使用activerecords,只想知道如何在Yii中以这种格式执行查询?
Yii::app()->db->createCommand(“从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和table1.tid=table3.id按table1.weight排序,table1.result”)->queryal()
。如果没有AR,就可以了。您想不使用activerecords,只想知道如何在Yii中以这种格式执行查询?
Yii::app()->db->createCommand(“从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和table1.tid=table3.id按table1.weight排序,table1.result”)->queryal()
。如果没有AR,就可以了。您想不使用activerecords,只想知道如何在Yii中以这种格式执行查询?
Yii::app()->db->createCommand(“从table1、table2、table3中选择table1.userid作为userid,table2.name作为username,table3.name作为tourname,其中table1.userid=table2.id和table1.tid=table3.id按table1.weight排序,table1.result”)->queryal()
。如果没有AR。