<code> // 获取所有的支出记录 public function gainHavingPayRecord(){ $m = M('pay_record'); $result = $m->order('payrecord_pay_time desc') ->join("LEFT JOIN x_account ON x_pay_record.payrecord_payer = x_account.account_id") ->field('account_phone,account_password,account_salt,account_alipay,account_createtime,account_cash,account_bank,account_isdelete',true) ->select(); dump($result[0]); return $result; }</code>
After that, all the data in the account table of the data output are filtered, and only the data in the pay_record table is output
<code>array(10) { ["payrecord_id"] => string(1) "1" ["payrecord_pay_time"] => string(1) "0" ["payrecord_payer"] => string(1) "1" ["payrecord_payment_type"] => string(1) "1" ["payrecord_item_category"] => string(1) "1" ["payrecord_item_son_category"] => string(1) "1" ["payrecord_sum"] => string(4) "3000" ["payrecord_record_time"] => string(10) "1467428218" ["payrecord_confirm"] => string(1) "0" ["payrecord_confirm_time"] => string(1) "0" }</code>
This is what the official document says
Is there any way to filter out these fields?
<code>->field('account_phone,account_password,account_salt,account_alipay,account_createtime,account_cash,account_bank,account_isdelete',true)</code>
In fact, I can also directly store the data I want to use in a table without using the join() method to reduce server pressure. But when I encounter this problem, I want to solve it. Once there is an urgent need to deal with it that day, It’s not impossible to get started with the data.
<code> // 获取所有的支出记录 public function gainHavingPayRecord(){ $m = M('pay_record'); $result = $m->order('payrecord_pay_time desc') ->join("LEFT JOIN x_account ON x_pay_record.payrecord_payer = x_account.account_id") ->field('account_phone,account_password,account_salt,account_alipay,account_createtime,account_cash,account_bank,account_isdelete',true) ->select(); dump($result[0]); return $result; }</code>
After that, all the data in the account table of the data output are filtered, and only the data in the pay_record table is output
<code>array(10) { ["payrecord_id"] => string(1) "1" ["payrecord_pay_time"] => string(1) "0" ["payrecord_payer"] => string(1) "1" ["payrecord_payment_type"] => string(1) "1" ["payrecord_item_category"] => string(1) "1" ["payrecord_item_son_category"] => string(1) "1" ["payrecord_sum"] => string(4) "3000" ["payrecord_record_time"] => string(10) "1467428218" ["payrecord_confirm"] => string(1) "0" ["payrecord_confirm_time"] => string(1) "0" }</code>
This is what the official document says
Is there any way to filter out these fields?
<code>->field('account_phone,account_password,account_salt,account_alipay,account_createtime,account_cash,account_bank,account_isdelete',true)</code>
Actually, I can also directly store the data I want to use in a table without using the join() method to reduce the pressure on the server. But I want to solve this problem, if there is an urgent need to deal with it that day. It’s not impossible to get started with the data.
<code>字段前加上表名或者表的别名: $result = M('x_account as acc')->join('x_pay_record as rec on rec .payrecord_payer = acc.account_id')->field('acc.字段1, acc.字段2, rec.字段3, rec.字段4')->select(); </code>
You must use the table name after joining because mysql does not know which field of which table you want to filter which field of that table
There should be, for example pay_record.acc
You can first use getLastSql to see how the sql statement is written. Join and field should be combined, so you can check your keywords again.
Add a test
In the field, add the table name field('table name.account_phone, table name.account_password, table name.account_salt, table name.account_alipay, table name.account_createtime, table name.account_cash, table name.account_bank, table name .account_isdelete',true)