I have a table in this order, i am trying to get data from this table where each row depends on the other to get the desired information i need.
ID USERNAME REFFERAL
1 user1 10
2. user2. 1
3 user3. 2
4 user4. 3
5. User5. 4
$sql = mysqli_query($server, “select refferal from profile where id=‘5’”);
$row1 = mysqli_fetch_assoc($sql);
$ref1 = $row[‘refferal’];
$sql2 = mysqli_query($server, “select refferal from profile where id=‘$ref1’”);
$row2= mysqli_fetch_assoc($sql2);
$ref2 = $row2[‘refferal’];
$sql3 = mysqli_query($server, “select refferal from profile where id=‘$ref2’”);
$row3= mysqli_fetch_assoc($sql3);
$ref3 = $row3[‘refferal’];
$sql4 = mysqli_query($server, “select refferal from profile where id=‘$ref3’”);
$row4= mysqli_fetch_assoc($sql4);
$ref4 = $row4[‘refferal’];
I would want to get all the usernames of of user4,user3,user2,user1 in one query if possible .. This is what i have tried so far but i don't think its is very efficent.