How can two data tables in Thinkphp use leftjoin to prevent the same field from being overwritten?

Source: Internet
Author: User
How can two data tables in Thinkphp use leftjoin to prevent the same field from being overwritten? M ('user')-> join ('left JOIN before_conditions on before_conditions.uid = User. id')-> where ($ mapBarCode)-> select ();

Both the user table and the before_conditions table have IDs as primary keys.

Now I want to get the id of the user table, but the query result is overwritten by the id of before_conditions. what should I do?


Reply to discussion (solution)

I know how to change the field alias. I know the native, but how can I change the database syntax of tp?

$ Model-> field ('Id, nickname as name')-> select ();

$ Name = M ('user')-> join ('left JOIN before_conditions on before_conditions.uid = User. id')-> where ($ mapBarCode)-> select ();
For ($ I = 0; $ I $ Name_ B = M ('before _ conditions ')-> where ("")-> find ();
$ Name [$ I] ['B _ id'] = $ name_ B ['id'];
}

Dump ($ name); the IDs of the output user table are not overwritten.

$ Model-> field ('Id, nickname as name')-> select ();


Succeeded, but I have dozens of fields except the id in the two tables. Do I need to add them all in the field?

$ Name = M ('user')-> join ('left JOIN before_conditions on before_conditions.uid = User. id')-> where ($ mapBarCode)-> select ();
For ($ I = 0; $ I $ Name_ B = M ('before _ conditions ')-> where ("")-> find ();
$ Name [$ I] ['B _ id'] = $ name_ B ['id'];
}

Dump ($ name); the IDs of the output user table are not overwritten.



I just hope that the database can be retrieved only once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.