Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:04:38+00:00 2026-05-24T12:04:38+00:00

Having tried several possibilities I have come to a stop. Without overloading the mysql

  • 0

Having tried several possibilities I have come to a stop. Without overloading the mysql server with hundreds of queries, this is what I am trying to achieve:

Here is the table

    CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `firstname` varchar(64) NOT NULL,
  `lastname` varchar(64) NOT NULL,
  `email` varchar(64) NOT NULL,
  `status` smallint(5) NOT NULL,
  `refchid1` int(11) NOT NULL,
  `refchid2` int(11) NOT NULL,
  `refchid3` int(11) NOT NULL,
  `refchid4` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

Explanation:

  1. I am trying to adjust a person’s status based on a complex tree. Each user has an id as denoted by the auto_increment id field.
  2. User A has his details entered into the table.
  3. User B is refered by User A, so when his details are entered refchid1 has the same id as User A.
  4. User C is refered by User B, his refchid1 becomes the id of User B and his refchid2 becomes the id of User A.
  5. User D is refered by User C, his refchid1 becomes that of User C, refchid2 that of UserB and refchid3 that of User A.

If you understand the referencing of the above, you are on the right track.

Sample Data of above description:

(6, 'Lars', 'Luna', 'Morbi.non.sapien@enimgravida.com', 25, 0, 0, 0, 0),
(7, 'Sonya', 'Cox', 'tellus@orci.org', 25, 6, 0, 0, 0),
(8, 'Aiko', 'Hodge', 'vestibulum.neque.sed@vel.edu', 25, 7, 6, 0, 0),
(9, 'Lillith', 'Bray', 'purus.Duis.elementum@necurnasuscipit.org', 25, 8, 7, 6, 0),
(10, 'Macey', 'Hayes', 'mi.pede@aliquetodioEtiam.net', 25, 9, 8, 7, 6);

What I am trying to accomplish is this:

  1. The default status is 25. (25,28,30,35,40) See this basically as a discount system, where the more people you refer and the more people they refer where you where the originating referer, you receive larger discounts.
  2. If User A has at least 10 unique users he has referenced as refchid1 he gains status.
  3. If User A has at least 10 uniuque users in refchid1 that each in turn has 10 unique users in refchid1 where User A is refchid2, he gains status.
  4. User A has 10 unique users in rechid1 that each have 10 unique users in refchid1 where user A is rechid2 that in turn have 10 unique users in refchid1 where user A is refchid3.
  5. etc.

As stated, the structure of testing is complex and I wish to do this without overloading the mysql server with millions of queries. The query should be an UPDATE query that will adjust the status of all matching users.

Does anyone have a solution of how I am going to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:04:39+00:00Added an answer on May 24, 2026 at 12:04 pm

    i should have created a list of user, and a seperate table for references,

    CREATE TABLE reference
    (
        reference_id SERIAL,
        new_user_id BIGINT UNSIGNED NOT NULL,
        refered_user_id BIGINT UNSIGNED NOT NULL,
        reference_depth INT UNSIGNED NOT NULL
    );
    

    and when you add a new user, if that user was refered by another user, add one row whit depth 1,

    INSERT INTO reference SET
        new_user_id = $new_user_id, 
        refered_user_id =  $refered_user_id, 
        reference_depth = 1
    

    then select all references linked to that user and add depth whit 1:

    INSERT INTO reference (new_user_id, refered_user_id, reference_depth)
    SELECT $new_user_id, refered_user_id, reference_depth +1
    FROM reference WHERE new_user_id = $refered_user_id;
    

    and then to calculate points

    SELECT
      SUM(
        IF(reference_depth = 1, 10, 0) 
        + IF(reference_depth = 2, 3, 0) 
        + IF(reference_depth = 3, 2, 0)
        + IF(reference_depth > 3, 1, 0)
      )
    FROM reference
    WHERE new_user_id = $user_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried several times to come with an answer to this question. I'm not
A bit like this from WordPress: Or this from MediaWiki: I have tried several
Having an issue here that I have tried everything I can think of but
Forgive me if this is a tried question, but I'm having a little difficulty
Since having blends is hitting perfomance of our game, we tried several blending strategies
I've tried several things... using Variables and Templates, and have made some slow progress.
I'm having trouble getting django's django.contrib.localflavor.au.forms to validate my form input. I have tried
I have tried several different ways to get a simple DataTemplate example to work.
I am trying to load a file.js dynamically with $.getScript. I have several select
Unfortunately, despite having tried to learn regex at least one time a year for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.