0

i have employeeinfo table and employeeloan table.. and i use this query:

$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'];
}

the result is

employee id: 1
amount: 1000
employee id: 1
amount: 500
employee id: 1
amount: 100

but what i want is to display like this:

employee id: 1
amount: 1000
amount: 500
amount: 100

sorry for my bad english. tnx in advance

1 Answers1

0

Normal hack can be done by below code

$i = 0 ;
while($row = mysqli_fetch_array($result)){
    if($i == 0)
        echo "<br>".$row['employeeid'];
    echo "<br>".$row['amount'];
    $i++;
}
urfusion
  • 5,528
  • 5
  • 50
  • 87
  • thank you sir.. actually it works.. i will use it now in my code.. but if there is other way i am very glad to know it.. anyways tnx again sir.. – robin-and adriano Apr 08 '17 at 09:51
  • could also check if mysql can do the job and work around this -> SELECT whatever_is_needed FROM table1 INNER JOIN table2 ON table1.otherid2=table2.otherid2 GROUP BY whatever_id – OldPadawan Apr 08 '17 at 10:47