It is necessary to create a sql query , with which you can find out whether the user is in the partners' branch.
I explain: suppose there is a user A who has partners B, C, D, these partners have their partners and so on. The result is a tree.
For example: there is such a branch of partners: A -> C -> F -> H -> P , you need to know if user H is in a branch where one of the predecessors is user C.
The maximum level of entry to search in the branch = 10, but perhaps it will be more or less.
Description of table fields:
id- partner's record IDuser_id- user IDpartner_id- user partner ID
CREATE TABLE IF NOT EXISTS `partners` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `partner_id` int(10) unsigned NOT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `partners_user_id_partner_id_unique` (`user_id`,`partner_id`), KEY `partners_user_id_partner_id_index` (`user_id`,`partner_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; PS Mysql v5.5
