2個表如何關聯查詢(thinkphp)

來源:互聯網
上載者:User
2張表
一:id uid name;
二;uid name;
知道這個是關聯,但是不會寫。就是就是將第一個表中的uid顯示成第二個表中的name,求解


回複討論(解決方案)

select b.name,a.name from biao1 as a ,biao2 as b where a.uid=b.uid

select b.name,a.name from biao1 as a ,biao2 as b where a.uid=b.uid

是用thinkphp來寫

$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' );

$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' );

謝了!!

關聯這東西在TP裡都是抽象好的
首先你的Model要繼承RelationModel類
裡邊要有一個protected $_link = array();這樣的數組,用來說明跟誰關聯
在調用的時候D()->relation(true)->...->select();就自動關聯了
只需要加個屬性就行了,看看官方介紹吧
http://doc.thinkphp.cn/manual/relation_model.html

關聯這東西在TP裡都是抽象好的
首先你的Model要繼承RelationModel類
裡邊要有一個protected $_link = array();這樣的數組,用來說明跟誰關聯
在調用的時候D()->relation(true)->...->select();就自動關聯了
只需要加個屬性就行了,看看官方介紹吧
http://doc.thinkphp.cn/manual/relation_model.html

手冊我有,我要的是多表查詢,這個手冊中沒怎麼說


$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' );

謝了!!


thinkPHP也支援直接查詢
$a=new Model();
$a->query(“sql語句”);

$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' );

join裡面的表面應該加首碼吧


$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' );

join裡面的表面應該加首碼吧


還要加什麼首碼碼?$a = new Model('a');
$list = $a->join('left join b on a.uid = b.uid' )->select();
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.