M('User')->join('LEFT JOIN before_conditions on before_conditions.uid=User.id')->where($mapBarCode)->select();
user表和before_conditions表都有id作为主键
现在我要得到user表的id,但查询出来的结果被before_conditions的id覆盖了,该怎么办?
回复讨论(解决方案)
我知道要改字段别名,原生的我知道,但是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); 输出结果user表的id几不会被覆盖
$Model->field('id,nickname as name')->select();
成功了,不过我这两张表除了id有几十个字段,要自己全部在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); 输出结果user表的id几不会被覆盖
我就是希望能只连接一次数据库就能取出
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:php中文网