Adding up hierarchy points

Asked

Viewed 63 times

0

My goal is to create a multi-level marketing system, with two teams.

Left Team and Right Team

Como funciona?

I’m having trouble keeping score.

My table looks like this: id_user | sponsor | leg( 0 left , 1 right) | points

Remembering that the network has no limit and that the sum of points on the left for example includes all points of the respective downlines.

I need help to make that score.

1 answer

0

To Add use the SQL function SUM(), but to use it you need to group your record with GROUP BY passing all fields you want to search, do not use c.*, just take the fields that are really needed for your application.

Example:

 SELECT c.id_usaurio,
       c.patrocinador,
       c.perna,
       sum(c.pontos) AS TotalPontos
FROM cic_ciclone_users p
INNER JOIN cic_ciclone_users c ON c.patrocinador = p.id_user
GROUP BY C.id_usuario,
         c.patrocinador,
         c.perna
  • Thank you so much! Just one more question, as I do to see the points of a particular user.

  • Just pass the code on your search SELECT PONTOS FROM cic_ciclone_user WHERE id_user = 1 where 1 is the id you want to search for. .

  • My first time in Stack, I’m sorry, for example, the user with id_user =1 , he is the sponsor of 2 and 3 , 2 is in leg 0 = left and 3 in leg 1 = right. My goal is to calculate the sum of points of the team left and right of the user... It’s a bit complex I admit, I hope you understand, your help is being excellent!

  • I could not understand, try to put in your question initial pictures of the table structure or some creation script

  • see if it’s a little clearer, I’m providing images of the table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.