<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> }
What I am querying here is the wifi_shop and wifi_authlist tables, and the connection condition is
wifi_authlist.shopid = wifi_shop.id
Generally, it should be noted that the data table contains prefixes, so the prefix should be added when joining
Just three table connections plus one 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();