Mysql How to sort row ORDER BY other row of record?

Codes here !

Moderators: gesf, Michalio

Post Reply
zac1987

My database tbl_user has the following columns :
Image

$user_id = 2;
$user_tree = $this->getAllRec("u.user_id",
"tbl_user u",
"WHERE u.Upline = '".$user_id."'
ORDER BY Right_id ASC");
print_r($user_tree);

Now the sequence it output (user_id 6) first then only output (user_id 5)

I want the array `$user_tree` to hold (user_id 5) first, then (user_id 6), how to do that?

I want to print (Left_id) first, then only print (Right_id). May I know how to do it?
User avatar
Michalio
Moderator
Moderator
Posts: 337
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

If I understood you correctly, you can add sorting on second column like

Code: Select all

ORDER BY upline DESC, Right_id ASC
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Post Reply