0
Hello, I have the following problem: I made a micro-social network for managers, where initially the registration is made only by invitation, thus "measuring" the influence of each one. My problem is in the ranking that currently carries out the count of invitations accepted by each person and the one that has more invitations accepted, obviously is at the top of the ranking:
SELECT
u.usr_id, b.ref_id, u.nome, b.c_hab, COUNT(*) AS qnt
FROM
tbl_user AS u
INNER JOIN
tbl_user b ON u.usr_id = b.ref_id
WHERE
b.c_hab = 1
GROUP BY u.nome
ORDER BY qnt DESC;
My problem arose when I was asked to count the direct invitations, that is, the manager sent to fulano1 (we will call level 1), the invitations that fulano1 sent (level 2) and so on. It’s confusing to explain, but basically a system of Multilevel Marketing and count the invitations in the ranking, only I have no idea how to accomplish this...
Follow the users table for further details:
CREATE TABLE `tbl_user` (
`usr_id` smallint(6) NOT NULL,
#Aqui é onde são armazenados as IDs de quem convidou você
`ref_id` smallint(6) DEFAULT NULL,
`nome` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`dt_nascimento` date DEFAULT NULL,
`cel` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`endereco` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`numero` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`senha` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`foto` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`token` char(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`c_hab` char(1) COLLATE utf8_unicode_ci DEFAULT '0',
`nivel` char(1) COLLATE utf8_unicode_ci DEFAULT '1',
`candidato` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
`dt_cad` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
If you can provide a possible solution, I would like to thank you in advance!
You do not have an exclusive table for invitations?
– Natan
No. The system currently works like this: The "root" user sends invitations to the people who will form the first level and they will receive this tag in the "ref_id". We did not create an "extra" table because until then had not requested anything of what was currently requested, IE, break all the requirements analysis that had been performed previously... Of course it might have been a mistake I haven’t made this table exclusive too kk
– Wilian Silva