我有employeeinfo表和employeeloan表.. 和我使用此查询:PHP的MySQL:连接两个表
$result=mysqli_query($con,"select tblemployeeinfo.employeeid, tblemployeeloan.amount from tblemployeeinfo left join tblemployeeloan on tblemployeeinfo.employeeid = tblemployeeloan.employeeid where tblemployeeinfo.employeeid = <employee id for example employee id 1>");
while($row = mysqli_fetch_array($result)){
echo "<br>".$row['employeeid'];
echo "<br>".$row['amount'];
}
结果是
employee id: 1
amount: 1000
employee id: 1
amount: 500
employee id: 1
amount: 100
,但我想要的是像显示这个:
employee id: 1
amount: 1000
amount: 500
amount: 100
抱歉我的英文不好。 TNX提前
你确定你的结果有员工ID?我没有看到你在查询中选择了 – hassan
对不起,先生...我的坏我会编辑我的帖子..据说这是tblemployeeid.employeeid –
[左连接没有重复行左表]的可能重复( http://stackoverflow.com/questions/22769641/left-join-without-duplicate-rows-from-left-table) –