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