> 백엔드 개발 > PHP 튜토리얼 > Thinkphp join 连接查询,thinkphpjoin_PHP教程

Thinkphp join 连接查询,thinkphpjoin_PHP教程

WBOY
풀어 주다: 2016-07-12 08:58:29
원래의
1211명이 탐색했습니다.

Thinkphp join 连接查询,thinkphpjoin

<span> 1</span> <span>public</span> <span>function</span><span> test ( )
</span><span> 2</span> <span>        {
</span><span> 3</span>             <span>$User</span> = M('authlist'<span>);
</span><span> 4</span>             <span>$rs</span> = <span>$User</span>-><span>join</span>('left join wifi_shop  on wifi_authlist.shopid = wifi_shop.id')->field('
<span> 5</span> <span>            wifi_authlist.id,
</span><span> 6</span> <span>            wifi_authlist.shopid,
</span><span> 7</span> <span>            wifi_authlist.routeid,
</span><span> 8</span> <span>            wifi_authlist.mac,
</span><span> 9</span> <span>            wifi_authlist.over_time,
</span><span>10</span> <span>            wifi_shop.id,
</span><span>11</span> <span>            wifi_shop.shopname,
</span><span>12</span> <span>            wifi_shop.pid,
</span><span>13</span> <span>            wifi_shop.trade,
</span><span>14</span> <span>            wifi_shop.province,
</span><span>15</span> <span>            wifi_shop.city,
</span><span>16</span> <span>            wifi_shop.area,
</span><span>17</span> <span>            count(wifi_authlist.mac) as times 
</span><span>18</span>             ')->where('wifi_shop.pid = %s',3)->group('wifi_authlist.mac')->order('over_time')->limit($Page->firstRow.','.$Page->listRows)->select()<span>;
</span><span>19</span>             dump(<span>$rs</span><span>);
</span><span>20</span>         }
로그인 후 복사

我这里查询的是 wifi_shop 跟 wifi_authlist 表,连接条件是

wifi_authlist.shopid = wifi_shop.id
로그인 후 복사

一般要注意的是数据表包含前缀, 所以再join里 要加上前缀

三个表连接再加一个join就行

<span> 1</span> <span>$rs</span> = <span>$User</span>-><span>join</span>('left join wifi_shop  on wifi_authlist.shopid = wifi_shop.id')-><span>join</span>('left join wifi_phonelist on wifi_authlist.mac = wifi_phonelist.mac')->field('
<span> 2</span> <span>            wifi_authlist.id,
</span><span> 3</span> <span>            wifi_authlist.shopid,
</span><span> 4</span> <span>            wifi_authlist.routeid,
</span><span> 5</span> <span>            wifi_authlist.mac,
</span><span> 6</span> <span>            wifi_authlist.over_time,
</span><span> 7</span> <span>            wifi_authlist.agent,
</span><span> 8</span> <span>            wifi_shop.id,
</span><span> 9</span> <span>            wifi_shop.shopname,
</span><span>10</span> <span>            wifi_shop.pid,
</span><span>11</span> <span>            wifi_shop.trade,
</span><span>12</span> <span>            wifi_shop.province,
</span><span>13</span> <span>            wifi_shop.city,
</span><span>14</span> <span>            wifi_shop.area,
</span><span>15</span> <span>            wifi_phonelist.mac,
</span><span>16</span> <span>            wifi_phonelist.phone,
</span><span>17</span> <span>            count(wifi_authlist.mac) as times 
</span><span>18</span>             ')->where('wifi_shop.pid = %s',<span>$pid</span>)->group('wifi_authlist.mac')->order('over_time')->limit(<span>$Page</span>->firstRow.','.<span>$Page</span>->listRows)->select();
로그인 후 복사

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1102858.htmlTechArticleThinkphp join 连接查询,thinkphpjoin 1 public function test ( ) 2 { 3 $User = M('authlist' ); 4 $rs = $User - join ('left join wifi_shop on wifi_authlist.shopid = wifi_shop.id...
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿