1
For example, in a select
in the bank, will be returned 5 records:
SELECT * FROM esc_usuarios
WHERE usu_indicador_codigo = '" . $_SESSION['codigo'] . "'
AND usu_situacao = 'ativo'"
Then I want to assign a value to each record, for example 10. Now I want to give a echo
in the sum of the value of all these records, i.e., 5 (select records) x 10 (value assigned to each record), then returning the number 50. How can I do that?
Update 0: New query
SELECT usu_nome, (
(SELECT (count(usu_codigo)*10) FROM esc_usuarios WHERE usu_indicador_codigo = a.usu_codigo AND usu_situacao = 'ativo')
+
(SELECT (count(usu_codigo)*5) FROM esc_usuarios WHERE usu_indicador_codigo in (
(SELECT usu_codigo FROM esc_usuarios WHERE usu_indicador_codigo = a.usu_codigo AND usu_situacao = 'ativo')
))
) usu_porcentagem
FROM esc_usuarios a
WHERE usu_codigo = 1
Hello friend, welcome. Come on, could you detail better how you would like to assign this number 10 to each row returned? would it be a column specific to the table consulted or would it be a variable within the loop in which you query the lines in php? because until now I think I could solve everything within the select itself... try to better detail your objective and the situation please.
– Inácio Régis
Hello! So, in this system, one person can register other people, and these other people register more people, forming a hierarchy. If the first one registers the second one, the first one gets 10 points, and if the second one registers the third one, the first one gets 5 points and the second one gets 10 points, then if you registered someone and they’re "active", 10 points for you, and +5 for each person you registered, register another
– Luann Sousa
@Then I wanted to show how many points a person already has, adding the 10’s that she registered, + the 5’s that the people she registered, and so on
– Luann Sousa
The score will stay only on 10 and 5, wanted to use as a variable within the loop
– Luann Sousa
then it is a query of users where the id is the session code and it is as "active", only applying this rule of 10 and 5 points for each registered user
– Luann Sousa
right, and how do we know who was registered by whom or who registered who? How is the table structure?
– user60252
in the table of registered users, this "usu_indicador_code" is a foreign key where it shows the id of who registered it, and in the registration form, it already inserts the id of the Session, ie, of who is registering
– Luann Sousa